PDA

Click to See Complete Forum and Search --> : Combo box control and MS Access


puttdaddy99
Oct 6th, 1999, 02:53 AM
I was wondering if anyone could explain how to populate the list property of a combo box in VB6 when the combo box has been bound to a data control (MS Access). I can get the first record to populate, but as far as the list is concerned, I'm lost. I was thinking of using a Do/Until Loop until the EOF is reached, but I cannot get it to work properly. If someone can point me in the right direction, I would really appreciate it.

Aaron Young
Oct 6th, 1999, 04:04 AM
I wouldn't use the standard Combobox/Listbox controls to bind to a Database, if you must bind a control, use the Databound List Controls in the Components list. Otherwise you could fill the Combobox yourself (Preferred Method):

Private Sub Form_Load()
Dim oDb As Database
Dim oRs As Recordset
Set oDb = Workspaces(0).OpenDatabase("Nwind.mdb")
Set oRs = oDb.OpenRecordset("SELECT FirstName FROM Employees", dbOpenForwardOnly)
While Not oRs.EOF
Combo1.AddItem oRs(0)
oRs.MoveNext
Wend
If Combo1.ListCount Then Combo1.ListIndex = 0
Set oRs = Nothing
oDb.Close
Set oDb = Nothing
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Off2Cabo
Oct 6th, 1999, 08:25 AM
Hello;

I haven't been able to achieve that with the "standard" list/combo box's. However,go to components and select the "Microsoft Data Bound List Controls", this will add DBListbox and DBCombobox on your menu. After you replace the list and/or combo box, you can then set the DataSource, Datafield, ListField, etc... to what you are wanting.
When in doubt, press F1, it will guide you through it.

Hope this helps

--Steph

------------------