Query with criteria paramenters from Main Form

mcranda

Registered User.
Local time
Yesterday, 19:13
Joined
Jul 6, 2012
Messages
14
I have numerous queries that have criteria parameters as: [forms].[Main Form].[list41]. The queriies are working fine. This works when one item is selected from the list box on the main form. However, now I have a mulitple list boxn instead of a single list box. What can I change my criteria to now to include multiple selections. The List41 just has all my customer numbers.
 
The only way I know of to pass items from a multi-select list box to a query is with Visual Basic for Application (VBA) code. Essentially you have to loop through the selected items and accumulate the customer numbers into a variable that you then use in the query or as a filter to a report of form that you open afterwards.

I've attached a sample database. You will want to select frmSelectPeople and then 2nd option (to select from a list). The VBA code is behind the button on the form. In this particular example the accumulated list is used to filter a report.
 

Attachments

I would like to pass value to query criteria from a listbox instead of using VBA. I don't really understand VBA quite yet. Anyone know how? Currently, like stated before my criteria was [forms].[Main Form].[list41]. This works for one customer that is listed in list41 but not when I pick more than one.
 
As far as I know; the only way is with VBA. I found this site that uses a simpler version of VBA code & gives a good explanation; perhaps it will help. I started out with VBA by reading a book called Access VBA for Dummies. It was written for an earlier version of Access; I assume that there is an updated version of the book out there by now.
 
Thank you. I am still really lost. I'll have to do a work around in my database until I get caught up on VBA. Thanks for the help :)
 
You're welcome. I'm sorry that I could not be of more help in providing a non-VBA solution.
 

Users who are viewing this thread

Back
Top Bottom