Multi-select multi column list box

M

merry_fay

Hi,

I'm using a 'simple' selection list box with multiple columns as criteria
for a query running on my form.

I've written the code:

For Each vItm In Me.lstBud.Column(0).ItemsSelected
strWhat = strWhat & "'" & Me.lstBud.Column(0).ItemData(vItm) & "', "
Next vItm

For Each vItm In Me.lstBud.Column(3).ItemsSelected
strWhat1 = strWhat1 & Me.lstBud.Column(3).ItemData(vItm) & ", "
Next vItm

(column(0) is text & column(3) is not)
but it's coming up with the error Run-time error '424': Object Required in
relation to 'Me.lstBud.Column(0).ItemsSelected'
Is there a way to use data from different columns in a list box as criteria
when multi-select is used?

Thanks
merry_fay
 
D

Daryl S

Merry_fay -

The ItemsSelected collection is on the control, not on a column, so remove
the .column(0) in your For Each constructs, like this:

For Each vItm In Me.lstBud.ItemsSelected
 
M

merry_fay

I've changed that bit, but I'm still struggling to set the criteria for the
different columns of the listbox.

This brings back the same criteria for each selection even though they're
different:
For Each vItm In Me.lstBud.ItemsSelected
strWhat = strWhat & "'" & Me.lstBud.Column(3) & "', "

And this has the same control problem:
For Each vItm In Me.lstBud.ItemsSelected
strWhat = strWhat & "'" & Me.lstBud.Column(3).ItemData(vItm) & "', "

How do I get it to use the data from columns other than the first one in the
listbox?

Thanks
 
D

Daryl S

Merry_fay -

Include the 'row' with the column - like this:

For Each vItm In Me.lstBud.ItemsSelected
strWhat = strWhat & "'" & Me.lstBud.Column(3, vItm) & "', "
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top