How can I load a comboBox (CmbFirstName)that is on frmCustomers inside a standard module(mdlCustomers).
Printable View
How can I load a comboBox (CmbFirstName)that is on frmCustomers inside a standard module(mdlCustomers).
Something like this
with frmCustomers.cmdFirstName
.Clear
.Additem Firstname or whatever
.ListIndex = 0
End With
Of course you would loop on the name additions.
Hope it Helps
If you want that procedure to be reusable, then you can so something like this:
Module Code
Form CodeCode:Public Sub LoadCombo(pCombo As Combobox)
With pCombo
.Clear
.AddItem "John"
.AddItem "Mike"
End With
End Sub
Code:Private Sub Form_Load()
LoadCombo Combo1
End Sub
Good call. :)
Possible you could funk it up even more by passing another value indicating what data to load, thereby being able to load any combo box.
LoadCombo Combo1, rs.FirstNames
Public Sub LoadCombo(Combo1 as ComboBox, rsData as Variant)
rs.movefirst
Combo1.Clear
Do
Combo1.Additem rsData.fields(0)
rsData.movenext
if rsdata.eof then exit do
loop
combo1.ListIndex = 0
Way Cool.....:)