Filling a list box with entries from a database

Pendaz
10-19-2004, 03:05 AM
i have a database with conaining names. and im making a visual basic program to edit/view/add records in that database. one of the fieilds in my database contains names. i want to be able to read all the names from the database and add them to a dropdown box in my vb program so that when a different name is selected from the dropdown, all the information for that name is displayed on my form


how would i go about this

Cheers
-Pendaz

Shurik12
10-19-2004, 03:20 AM
Hi,

Have you tried to search the forum? This (fill listbox/combobox question) has been asked many times...

Regards,
Shurik.

Pendaz
10-19-2004, 03:30 AM
yes i have searched, i couldnt find what i was looking for. any suggestions?


i have the basic idea down:-


with frmassign.data.recordset
.movefirst

for i = 1 to 10 ' there are 10 records in the database field and i has been declared as an integer

frmassign.LstDrivernames.addnew .(dont know what to put here?!?!)
.movenext
if eof = false then
next
else
end
end if

Shurik12
10-19-2004, 05:12 AM
>.(dont know what to put here

rs.Fields("FielName").Value

NEOLLE
10-19-2004, 06:12 AM
Since you already used the With function
You can do .Fields("FieldName").Value

:)

Demon Cleaner
10-19-2004, 07:04 AM
Just a tip.

You have to be carefull about what you "seeing" in your list box. Since you said that you're populating names there is a chance that these names may be repeated sometimes. So in your listbox you may see something like this

e.g.(3 NEO's here!)

JOHN
MICHAEL
NEO
NEO
NEO
MORPHEUS

In order to avoid this try to form your data a little bit before you add them to your list box.

e.g.

.AddItem rs.Fields("name").Value & " " rs.Fields("surname").Value

or

.AddItem rs.Fields("id").Value & " - " rs.Fields("name").Value

or whatever...

Later you could use some string manipulation functions in order to retrive the desired value.

Pendaz
10-19-2004, 08:09 AM
ok thanks for your help you guys :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum