A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

using Control to populate combobox



 
 
Thread Tools Display Modes
  #1  
Old March 29th, 2010, 12:33 PM posted to microsoft.public.access.forms
Ingo Hanke
external usenet poster
 
Posts: 2
Default using Control to populate combobox

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

  #2  
Old March 29th, 2010, 01:30 PM posted to microsoft.public.access.forms
BruceM via AccessMonster.com
external usenet poster
 
Posts: 448
Default using Control to populate combobox

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/For...forms/201003/1

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.