msaccess list box in a query

Guys I am looking to return data from a query using a form that has multi select list boxes on it.
What I want to happen is I open my form (Main_Menu) select my details and double click the list box (lstCategory) gets populated I then double click the (lstEmpCat) which also populates I choose from the list my multiple selections and then press the button (Preview) on pressing this I want the query (Build) to populate based on this but I am needing some assistance.

Can any one help

I will attach the database to help.

to help you understand the list box (lstCategory) refers to the column in my query (PAYROLL_LIST_ID) and the list box (lstEmpCat) refers to the column in my query (EMP_CAT_NAME)
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Your database used tables linked to an ODBC datasource, and we can't run it. You'd need to convert that to local tables, and upload again. When doing this, be sure to remove any sensitive or personal data from those tables.

Also, we need more information about your process - Do you mean you want your query to filter on the multiple items you've selected in a listbox? If so, you can't do that directly in a query, and must create a function that will collect the items selected. Your query can then refer to that function for filtering.
DarrenJacksonAuthor Commented:
Hi Scott yes this is exactly what I am after. I will see what I can do regarding the sample data
Here's an example database that might prove useful.  It includes two examples using a listbox.  One creates a filter and applies it to the subform and the other modifies the RecordSource query for the subform.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

DarrenJacksonAuthor Commented:
Hi Pat I will take a look now but I have a sample database ready for extra help with this
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
We're not really here to "fix" your database for you, but rather to give you advice on how to fix it. Pat's example shows you how to do this, so you can take that knowledge and apply it to your database.

Here's an article that shows how to do that. Notice the code in Method 2, Item #5. In that, they're looping through the ItemsSelected property of that listbox to gather the user selections, and they create a comma-delimited list to use as a WHERE clause:

 For Each Itm In ctl.ItemsSelected
      If Len(Criteria) = 0 Then
         Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
         Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) _
          & Chr(34)
      End If
   Next Itm

Note that "ctl" in this instance is your listbox you want to use to gather the user selections.

They also directly alter the querydef, which you would do in your Preview button's click event:

 ' Modify the Query.
   Set DB = CurrentDb()
   Set Q = DB.QueryDefs("MultiSelect Criteria Example")
   Q.SQL = "Select * From Orders Where [CustomerID] In(" & Criteria & _
DarrenJacksonAuthor Commented:
Thanks Scott I understand and appreciate your help as always. Ill look through this and Pat's and come back if I am struggling to make sense.

Again thankyou
DarrenJacksonAuthor Commented:
I have worked out a solution

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.