ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform Combobox Excel 2003 (https://www.excelbanter.com/excel-programming/415104-userform-combobox-excel-2003-a.html)

eggpap

Userform Combobox Excel 2003
 
Hello,

is it possible to link programmatically a userform combobox to a table of
one external Access mdb file?

Thanks, Emiliano



Office_Novice

Userform Combobox Excel 2003
 
In short Yes. Not an easy task but very doable, Here is what you need to do,
first create a referance to Microsoft DAO 3.6 Object library
Tools-References-Microsoft DAO 3.6 Object library
then in the UserForm_Initialize()
YourProcedureName
End Sub
in a Standard code module place the following

Public Sub YourProcedureName
Dim DAO As DAO.DBEngine
Dim YourDB As DAO.DataBase
Dim YourRS As DAO.Recordset
Dim i As Integer
Dim Count As Integer

Set DAO = New DAO.DBEngine
Set YourDB = DAO.OpenDatabase("C:\Documents and Settings\Desktop\db1.mdb")
Set YourRS = YourDB.OpenRecordset("Sampledb")
Count = YourRS.Fields.Count

For i = 0 To Count - 1
UserForm1.ComboBox1.AddItem YourRS.Fields(i).Name
Next

Set YourRS = Nothing
Set YourDB = Nothing
Set DAO = Nothing
End Sub
You will have to change the example to suit your database name and recordset
but the rest should work fine. Good luck.

"eggpap" wrote:

Hello,

is it possible to link programmatically a userform combobox to a table of
one external Access mdb file?

Thanks, Emiliano





All times are GMT +1. The time now is 11:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com