Public Sub fill_combo(cmb As ComboBox)
Dim sSQL As String, rs As ADODB.Recordset
On Error GoTo L_Err
cmb.Clear
Set rs = New ADODB.Recordset
sSQL = "SELECT * From tblTest order by [name]"
rs.Open sSQL, cnn
If rs.EOF And rs.BOF Then GoTo L_Res
If Not rs.BOF Then rs.MoveFirst
Do While Not rs.EOF
cmb.AddItem rs("Name")
cmb.ItemData(cmb.NewIndex) = rs.Fields(fld & "ID")
rs.MoveNext
Loop
rs.Close
L_Res: If cmb.ListCount Then cmb.Text = cmb.List(0)
L_Exit: Set rs = Nothing: Exit Sub
L_Err: MsgBox Err.Description & " (" & Err.Number & ")", vbExclamation, "fill_combo": GoTo L_Exit
End Sub
|