VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Fill list combo box from database

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

Rate Fill list combo box from database



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


Download this snippet    Add to My Saved Code

Fill list combo box from database Comments

No comments have been posted about Fill list combo box from database. Why not be the first to post a comment about Fill list combo box from database.

Post your comment

Subject:
Message:
0/1000 characters