Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate combobox in Microsoft Visual Basic 6.0

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.

like image 764
Ish Avatar asked Dec 05 '25 10:12

Ish


1 Answers

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.

like image 188
Antagony Avatar answered Dec 08 '25 01:12

Antagony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!