You can search on the basis of multiple selections in a list box by setting its MultiSelect property to Simple or Extended. For an illustration of how to return rows which match any or all of the selected take a look at SearchDemo.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
In this little demo file, clicking on the Select Criteria for Report button opens a dialogue form in which one or more selections can be made in a list box. The following code in the Click event procedure of the OpenReport button then opens a report filtered on the basis of the selections in the list box:
Private Sub cmdOpenReport_Click()
Const REPORTCANCELLED = 2501
Const MESSAGETEXT = "No matching items to report."
Dim varItem As Variant
Dim strStockIDList As String
Dim strCriteria As String
Dim ctrl As Control
Set ctrl = Me.lstStock
If ctrl.ItemsSelected.Count > 0 Then
For Each varItem In ctrl.ItemsSelected
strStockIDList = strStockIDList & "," & ctrl.ItemData(varItem)
Next varItem
' remove leading comma
strStockIDList = Mid(strStockIDList, 2)
If optAnyOrAll = 1 Then 'any item stocked
strCriteria = "StoreID IN(SELECT StoreID " & _
"FROM StoreStock " & _
"WHERE StockID IN(" & strStockIDList & "))"
Else 'all items stocked
strCriteria = "StoreID IN(SELECT StoreID " & _
"FROM StoreStock " & _
"WHERE StockID IN(" & strStockIDList & ") " & _
"GROUP BY StoreID " & _
"HAVING COUNT(*) = " & ctrl.ItemsSelected.Count & ")"
End If
On Error Resume Next
DoCmd.OpenReport "rptStoreStocks", _
View:=acViewPreview, _
WhereCondition:=strCriteria
Select Case Err.Number
Case 0
' no error
Case REPORTCANCELLED
' anticipated error
MsgBox MESSAGETEXT, vbInformation, "Warning"
Case Else
' unknown Error
MsgBox Err.Description, vbExclamation, "Error"
End Select
Else
MsgBox "No items selected", vbInformation, "Warning"
End If
End Sub