A family of Microsoft relational database management systems designed for ease of use.
You're mixing up your criteria variables, here and there. Try this version:
'------ start of code ------
Private Sub Okay_2_Click()
Dim DB As Database
Dim Q As QueryDef
Dim strSubjCriteria As String
Dim strCatCriteria As String
Dim Itm As Variant
' Build a list of the Subject selections.
With Me!LstSubject
For Each Itm In .ItemsSelected
strSubjCriteria = strSubjCriteria & "," & Chr(34) & .ItemData(Itm) & Chr(34)
Next Itm
End With
If Len(strSubjCriteria) = 0 Then
MsgBox _
"You must select one or more items in the list box!", _
vbExclamation, _
"No Selection Made"
Me!LstSubject.SetFocus
Exit Sub
Else
' Trim off leading comma.
strSubjCriteria = Mid$(strSubjCriteria, 2)
End If
' Build a list of the Category selections.
With Me!LstCategory
For Each Itm In .ItemsSelected
strCatCriteria = strCatCriteria & "," & Chr(34) & .ItemData(Itm) & Chr(34)
Next Itm
End With
If Len(strCatCriteria) = 0 Then
MsgBox _
"You must select one or more items in the list box!", _
vbExclamation, _
"No Selection Made"
Me!LstCategory.SetFocus
Exit Sub
Else
' Trim off leading comma.
strCatCriteria = Mid$(strCatCriteria, 2)
End If
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("MultiSelect")
Q.SQL = "Select * From BabyData Where [Subject] In(" & strSubjCriteria & _
") And [Category] In (" & strCatCriteria & _
");"
Q.Close
' Run the query.
DoCmd.OpenQuery "MultiSelect"
End Sub
'------ end of code ------