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

using multiple values from a list box in a query

Status
Not open for further replies.

kenjones

Technical User
Jul 19, 2002
4
0
0
GB
Further to my previous message, I have set up a list box to allow multiple selections. How can I use these multiple selections in a query to select rows based on each value. the syntax I have (... = [forms]![formname]![listboxname]..)does not seem to work.
 
Hi Ken,
You can't use the list box the way you have mentioned. You must iterate thru the ItemsSelected collection to get all the values.

You could write a public function as below:

Public Function getCriteria() as String
dim x as variant
dim str as string
str=""
For each x in [Forms]![yourFormName].List1.ItemsSelected
str=str & [Forms]![yourFormName].List1.Column(0,x)
Next x

getCriteria=str
End Sub

In the query criteria, you could use

In getCriteria()

I have not tried this code but hope this helps. Let me know what happens.

With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top