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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populating a listbox from fields in a record from an access database

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
CA
I am trying to take fields from n access database and place them in a listbox on my vb form can I do this and how
the names of the fields are songname1, songname2, songname3 ...
can I set up a loop to deal with this ?
 
Johnny, what d'ya mean Barq's has bite? Johnny?
;P

Well, it all depends on how you're accessing hte access database. If you're using an ADODB control on your form, then all you have to do is point the ListBox.DataSource and ListBox.DataField properties to that control.

However, if you're doing it in code (which I prefer over those ADODB toys) then what you should do is create a connection to the db in code, then create a recordset based off of what you want to fill the listbox with
("Select * From SongNames"), and then use your loop to cycle through the recordset and fill the listbox.

For Not rs.EOF
ListBox.AddItem rs.Fields("SongName")
rs.MoveNext
Next

Thats off the top of my head, and may not be syntactically correct, but you get the idea. Let me know if I can help any further,

Laterz,
Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top