Programatically populate a combo box from a recordset
Posted on 2008-06-17
I have work out the following code to populate my combo box:
'Populating dropdown of Format
Dim sqlFormat As String
sqlFormat = "SELECT tblRef_Chartez.libelle FROM tblRef_Chartez ORDER BY tblRef_Chartez.libelle ASC"
Set rs = con.OpenRecordset(sqlFormat)
If rs.EOF Then
'Me.cboFormat.AddItem ("Table is empty")
Me.cboFormat.RowSource = "Table est vide"
While (Not (rs.EOF))
Me.cboFormat.RowSource = Me.cboFormat.RowSource & (rs(0))
'End of dropdown
As the method AddItem doesn't work on Ms Access 2000, I did some research and I found that I can populate the combo box by RowSource method.
But to my surprise, I can get the item in the combo box but at one row level only. All the items are shown mixed together on one line only.
Can someone help me out please.
Should I use another method other than RowSource or my code contains errors.