using Control to populate combobox

I

Ingo Hanke

Dear,

I have a form where I have to populate different combo boxes at
different stages with data from a separate database.
I’m trying to write a Function that would easily repeat the task, the
main problem is specifying what combo box to use. This is what I
think it should look like.


Public Sub LoadCB(cbName As Control, SelectionString As String)
cbCount = 0
Set rstLoadCB = VMSDatabase.OpenRecordset(SelectionString)
With rstLoadCB
For each X in rstLoadCB
cbName.AddItem (current record)
Next
End If
end With
End Sub


I’m not having any luck with all my variations of the code, could
someone please help me

Regards Ingo
 
B

BruceM via AccessMonster.com

If you intend to open a database you need to let Access know where it is,
maybe something like this:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strPath As String, strMsg As String, strTitle As String

strPath = "\\ServerName\ShareName\DatabaseName.mdb"
Set db = OpenDatabase(strPath)
Set rs = db.OpenRecordset("TableName", dbOpenDynaset)

AFAIK you can't loop through a recordset as you have shown, but in any case
what is X supposed to be? It seems you may be trying to loop through
controls, but in that case you won't find them in a recordset.

Why not link to the tables you need? It's difficult to sort out what you are
trying to do, but some more explanation would help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top