Ray,
Not sure what you have, but the vba should be parsing the ItemsSelected and build a
string such as IN("BMI","A1c")
and this would be the criteria for a where clause.
Here's a sample from a form I have. I have selected a supervisor and the listbox identifies the Employees he/she supervises. You can select several items from the listbox.
The code below loops through the list box's ItemsSelected and creates the info for a where clause. In my case the Where clause limits a Report to these Employees.
I have added DEbug.Print statements to show the value of sWho on each pass of the loop, and a debug.print to show the final In () clause.
button click code
Code:
Private Sub Command4_Click()
Dim vItem As Variant
Dim sWho As String
Dim sIn As String
10 sWho = ""
20 sIn = ","
30 For Each vItem In Me.List2.ItemsSelected
40 sWho = sWho & Me.List2.ItemData(vItem)
50 sWho = sWho & sIn
Debug.Print sWho
60 Next vItem
70 sWho = Mid(sWho, 1, Len(sWho) - 1) 'get rid of trailing comma
80 sSQL = "empid IN (" & sWho & ")"
Debug.Print sSQL
90 DoCmd.OpenReport "Employee", acViewPreview, , sSQL
End Sub
Output of the Debug.print statements. In my case the ItemsSelected were numbers.
Code:
2,
2,3,
2,3,8,
2,3,8,9,
empid IN (2,3,8,9)