I wrote this code several years ago in VB6. I was using an Access database on the backend. Hope this helps.
Code:
Public Sub PopProgrammer()
'This fuction populates Assigned Programmer's combobox field on the FrmUtility form
'when the application is executed.
Set WrkSpce = CreateWorkspace("", "admin", "", dbUseJet) ' Create the workspace
Set db = DAO.OpenDatabase("C:\Program Files\IssuesLog\MsgUtil.mdb", False, False) ' Set the Database
SQLString = "SELECT * FROM ProgNameTbl" ' this query selects all of the records in the table
Set QryTbl = db.CreateQueryDef("") ' Create a Query definition object
QryTbl.SQL = SQLString ' Set the Query def object to the SQL String
Set rs = QryTbl.OpenRecordset ' execute the query
If rs.BOF = True And rs.EOF = True Then ' If EOF or BOF then...
Reply = MsgBox("An Application error has occurred, Contact the application administrator.", vbOKOnly, "Uh Oh!")
'...Display message box
Else 'otherwise
rs.MoveFirst 'move to first record on recordset
While rs.EOF = False 'perform loop until EOF
CboProgrammer = rs.Fields("AssgProg") 'Assign field in record to variable
frmUtility.cboAsgnProg.AddItem CboProgrammer 'Add item to Combo box
rs.MoveNext 'move to next record
Wend 'End While loop
rs.Close 'Close recordset
db.Close 'Close Database
End If 'End if
End Sub