From: Ingo Hanke on
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

From: BruceM via AccessMonster.com on
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.

Ingo Hanke wrote:
>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

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/201003/1