List Box Multiple Selection for query criteria

carvind

Registered User.
Local time
Today, 11:54
Joined
Nov 10, 2000
Messages
22
I have a list box on a form and I would like to give the user the option to select multiple items from the list. How do accomplish this and pass on a single string to the query to retrive the records based on the multiple items. As I am not familiar with writing a code, I would greatly appreciate a complete solution for it.

Thanks in advance
 
I'll be watching this thread too. Currently, I do not believe you can select more than one choice from a list box. It would require more than one to send multiple strings to the query.
 
carvind -

Send me your email address and Access version and I will send you a demo.

jwindon -

I have sent you an Access97 version and it will upgrade to Access2000 if that is what you are using.
 
Jack's sample may give you a better look at the code, but basically here it is:

Dim varItem As Variant
Dim strWhere As String

For Each varItem In Me![YourListBoxName].ItemsSelected
strWhere = strWhere & "YourUniqueIDField =" _
& Chr(39) & Me![YourListBoxName].Column(0, varItem) & Chr(39) & " Or "
Next varItem

strWhere = Left(strWhere, Len(strWhere) - 4) 'Remove the last " Or "

DoCmd.OpenForm "YourFormName", , , strWhere

This is only an example. the names of the objects need to be the names of your objects.

Also the Multi Select property for the listbox needs to be set to Simple or Extended.

HTH
RDH

[This message has been edited by R. Hicks (edited 08-26-2001).]
 
Ricky's code is much more straight forward than mine! I use some code and a lot of sleight-of-hand to stick the selected items into an In() statement. I think that you both should seriously consider using Mr. Hicks' code as it is far simpler. I am revising my demo Ricky!



[This message has been edited by Jack Cowley (edited 08-26-2001).]
 
Man I learn so much stuff on this forum its unbelievable.
Thank you.

D.J.
 
Thanks to both of you. I will play with that too later. I'm so snowed with work right now!!!! I like the weekends when I can sit and read the forum uninterrupted!
 
Thanks Jack and Ricky for your help. I was able to accomplish what I need to.
 
can you send me this demo?
i need a form with 5 drop down menus and when i make choises for any of them to run the query
like filter by form
thank you
 

Users who are viewing this thread

Back
Top Bottom