Avatar of simpkinst
simpkinst
Flag for United States of America asked on

Multiple List box selection

I have a multi select list box on a form with a pretty intensive select query and I would like to use what the user selects as the criteria for the intensive query. I have a function that gets the information correctly but when it returns the selection to the query, it is like it returns nothing or something that the query doesn't like. Below you will see the function:

Function SQL_Criteria() As String
Dim varItem As Variant
Dim strCriteria As String
Dim ctrl As Control

Set ctrl = [Forms]![frmMain1].MPN
strCriteria = "'"

For Each varItem In ctrl.ItemsSelected
    strCriteria = strCriteria + ctrl.Column(0, varItem) & "','"
Next varItem
If strCriteria = "'" Then
    SQL_Criteria = "Like '*'"
Else
    SQL_Criteria = "IN(" & Left(strCriteria, Len(strCriteria) - 2) & ")"
End If
   
End Function

I put the call to this function in my where clause, but it doesn't seem to run correctly. It doesn't give me an error just an empty table.

Thanks in advance for all your help.
Microsoft Access

Avatar of undefined
Last Comment
simpkinst

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PatHartman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
PatHartman

The appropriate way to close this would be to post your solution and then select that as the answer.
simpkinst

ASKER
I noticed that the querydef was adding in an "=" sign to the code so I figured out that I had to build the SQL myself as noted above, I had not seen this answer by the time I had figured it out. Thank you, for your help.
simpkinst

ASKER
Thanks for your help.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy