I want to populate a Combo Box from a recordset (I want to list every values of a column).
Thanks ! :-)
Printable View
I want to populate a Combo Box from a recordset (I want to list every values of a column).
Thanks ! :-)
If your recordset is called rs and the field in the database that you want in the combo box is field1 then once you have opened the recordset
do until rs.eof
Combo1.Additem rs!field1
rs.Movenext
loop
Real thanks.
There was a problem if thfield is null,to correct that you just have to make this test in the loop:
If recordset.field <>" " then
......
End If
I think this chech <> "" is not apropriate.
Take a look at the IsNull() function.
Hi,
The most straightforward way, apparently is
to read one by one the records from the recordset and to add them to the list/combo box.
This, however, is a little awkward approach, because with larger databases the time to load the control will be really long.
As the smart people know that we will encounter such problems, they have made databound controls that can be linked to the recordset. They work really fast.
You may wish to search a little about this databound controls in the MSDN.
If you do not want to "waste" your time searching for these databound controls you can do a thing to speed up your loading process.
Before starting the loop that fills the combo/list box one by one just make this combo/list box unvisible i.e. set its visible propery to false. This will speed up the process
considerably.
Regards,
Valery Nikolov
http://listen.to/quark