by Shadab Azeem Rahil (8 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 6th July 2002
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Fill list combo box from database
API Declarations
'[email protected]
'http://www.akaaz.cjb.net
String)
On Error GoTo Errors
Dim rs As Recordset 'Declare a recordset
Dim sql As String 'Declare a string to hold the SQL statement
cboBox.Clear
sql = ""
sql = "SELECT " & IDField & ", " & descField & " FROM " & strTB
Set rs = db.OpenRecordset(sql, dbOpenForwardOnly)
With rs
Do Until .EOF 'Loop until the End of the recordset
cboBox.AddItem rs(descField)
cboBox.ItemData(cboBox.NewIndex) = rs(IDField)
.MoveNext
Loop
.Close
Debug.Print cboBox.Name & " was populated"
End With '(rs)
Set rs = Nothing 'Release the variable
Exit Sub
Errors: 'Error handler
If Err.Number <> 0 Then
MsgBox ("Error #: " & str(Err.Number) & Err.Description)
Exit Sub
End If
End Sub