Reputation: 671
I have a combo box in Microsoft Visual Basic 6.0. I have to add items to the combo box. These items are stored in SQL database within a table in Column1. I am not sure how to get those items to display in combobox on run time so the user can select different options.
Note: The table only has one column.
Here is the code I have written so far:
'Public Function GetProvincialRidingRst() As ADODB.Recordset
'
' Dim rst As ADODB.Recordset
' Dim strSQL As String
'
' strSQL = "Select * from ProvincialRidings"
'
' Set rst = New ADODB.Recordset
' rst.ActiveConnection = cn
' rst.Open strSQL, , adOpenKeyset, adLockBatchOptimistic
'
' Set GetProvincialRidingsRst = rst
'
'End Function
I am not sure how to process from here.
Upvotes: 3
Views: 8849
Reputation: 1780
Once you have a recordset it's just matter of looping through the records and adding them to the ComboBox. Something like this ought to do it:
Combo1.Clear
With myRS
Do While Not .EOF
Combo1.AddItem ![myColumn]
.MoveNext
Loop
.Close
End With
Obviously, you'll need to replace myColumn
with the actual column name from the table.
Upvotes: 5