PDA

View Full Version : listbox issue



saledan
07-08-2008, 08:48 AM
Hi to everyone.
I have an issue with listbox.
When click on a button, i run a query with ADODB and I use
Do Until rec.EOF
Loop
to get each result from the query.
I have a listbox with 6 columns, and i would like to populate the listbox with the query results, but with .addItem function, for example
resultSearchListBox.AddItem (rec.Fields("surname").Value) i add value just only into the first column. How can I add values into the other columns, for example rec.Fields("name").Value into the 2nd...etc..?
I tried some times with different codes, but I always received error from execution or add value in the first column.

Please may you help me?

Thanks a lot
(p.s.: sorry for my english, i hope that you understand my issue)

JimmyTheHand
07-09-2008, 04:35 AM
Hi and welcome to the VBAX Forums :hi:

Check ADODB.Getrows method. I don't exactly remember how to use it just now, and don't have the time to experiment, but if memory serves, it will be something like this:
resultSearchListBox.Column = rec.GetRows
'or
resultSearchListBox.List = rec.GetRows

It puts all records into the list in one single step. You have to make sure that the number of fields in the recordset is the same as the number of columns in the listbox.

HTH

Jimmy

saledan
07-10-2008, 01:26 AM
Hi and welcome to the VBAX Forums :hi:

Check ADODB.Getrows method. I don't exactly remember how to use it just now, and don't have the time to experiment, but if memory serves, it will be something like this:
resultSearchListBox.Column = rec.GetRows
'or
resultSearchListBox.List = rec.GetRows

It puts all records into the list in one single step. You have to make sure that the number of fields in the recordset is the same as the number of columns in the listbox.

HTH

Jimmy

thank you, but it doesn't work.
GetRows returns an array. But the problem is to assign values into the listbox. I received error. For example with
resultSearchListBox.Column = rec.GetRows Argument not optional. Column because expression.Column(Index, Row) ..
resultSearchListBox.List = rec.GetRows
.List doesn't exist
I tried also with resultSearchListBox.RowSource = rec.GetRows Type mismatch.

I don't know how to use listbox with more columns :banghead: :dunno :banghead: :(

Carl A
07-10-2008, 05:32 PM
Try setting your listbox row source property to value list and separate your columns with a semi-colon.

resultSearchListBox.AddItem (rec.Fields("surname").Value) ; (rec.Fields("NextColumn").Value
HTH

saledan
07-10-2008, 11:57 PM
Try setting your listbox row source property to value list and separate your columns with a semi-colon.

resultSearchListBox.AddItem (rec.Fields("surname").Value) ; (rec.Fields("NextColumn").Value
HTH

resultSearchListBox.AddItem (rec.Fields("user_id").Value) & ";" & (rec.Fields("surname").Value) it works.

Many thanks