Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listing multiple database items in one combo box

Status
Not open for further replies.

jschwick

Programmer
Apr 2, 2002
2
AU
I'm looking to link a combobox with a database so that i can display all entries from a particular field of the database. How can i do this???
 
Hi,
You need a connection between VB and the DB, a Recorset, a query, a combobox and a loop.

Ex:
'Assuming the connection is open
Dim RS As New ADODB.Recordset
Dim sSQL AS String

'Don't sort the query, you can do it in the combobox,
'it will be faster
sSQL = "SELECT Client_ID, Client_Name FROM Client"

RS.Open sSQL, adoConnection
While Not RS.EOF
cboClient.AddItem RS.Fields(1)
cboClient.ItemData(cboClient.NewIndex)=RS.Fields(0)
RS.MoveNext
Wend

RS.Close
Set RS = Nothing

that should do it!!!
Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top