Hi,
I am pulling data from a SQL table to build a combo box in Visual Basic. Is there a way to use 2 columns for the combo box: one that displays the choice and another to be the actual value?
I have two columns: "Description" and "ID", I want the users to be able to see the Description column as the choices, and the "ID" column will be underlying as the actual value.
Here is my code that only displays the "Description". Could someone help me add in "ID"? Thanks.
Private Sub LoadCombo()
Dim rsData As ADODB.Recordset
Dim strSQL As String
cboNYScenDesc.Clear
strSQL = "SELECT Description, ID " & _
"FROM Table1 " & _
"ORDER BY Description "
Set rsData = New ADODB.Recordset
rsData.Open strSQL, cnnDB, adOpenDynamic, adLockOptimistic
With rsData
If Not .BOF And Not .EOF Then
.MoveFirst
Do While Not .EOF
cboCombo.AddItem Trim(!Description)
.MoveNext
Loop
End If
.Close
End With
Set rsData = Nothing
End Sub