Reputation: 12353
I have a Combo box on a form and want to populate from table with vba code. The query has two columns proc_name and then ID and have set combo box column count as 2, but when form is loaded I see ID first and then proc_name. Why is this happening?
For the other combo box with similar table structure they show column order how I have defined in the query.
Private Sub Form_Load()
Dim strSQL As String
createCon
strSQL = "Select proc_name, ID from tblProcess"
Set objRecordset = New ADODB.Recordset
objRecordset.Open strSQL, objConnection, adOpenKeyset, adLockOptimistic
If Not (objRecordset.EOF And objRecordset.BOF) Then
Set Me.cmbProcess.Recordset = objRecordset
End If
objRecordset.Close
Set objRecordset = Nothing
End Sub
Upvotes: 1
Views: 632
Reputation: 97131
When the Recordset
columns are loaded into the combo box, it appears they are processed in alphabetical order (ID
before proc_name
).
Alias the fields in your SELECT
field list so they are processed in the order you wish:
strSQL = "Select proc_name AS f1, ID AS f2 from tblProcess"
Upvotes: 2