I have 11 multi listboxes and trying to collect what the user puts in each listbox and send all that information to my query which is already set up and named and the listboxes just work as a filter in the query because the query pulls everything I need. The listboxes are just there to place filters on each of the 11 columns. Then I want to pass it to a subform that I have already created for the results. Here is my code so far and I am lost as to how to take the strwhere and pass the filters on to the query.
Code:
Private Sub command8_click()
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'make sure a selection has been made
If Me.List1.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one line of business."
Exit Sub
End If
If Me.List2.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one year."
Exit Sub
End If
If Me.List3.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one month."
Exit Sub
End If
If Me.List4.ItemsSelected.Count = 0 Then
MsgBox "Must select as least one state."
Exit Sub
End If
If Me.List5.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one business unit."
Exit Sub
End If
If Me.List6.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one plan/product name."
Exit Sub
End If
If Me.list7.itemselected.Count = 0 Then
MsgBox "Must select at least one condition category."
Exit Sub
End If
If Me.list8.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one meausre."
Exit Sub
End If
If Me.list9.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one sub measure."
Exit Sub
End If
If Me.List10.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one facing.'"
Exit Sub
End If
If Me.List11.ItemsSelected.Count = 0 Then
MsgBox "Must select at least one communication type."
Exit Sub
End If
'add selected values to string
Set ctl = Me.List1
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List2
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List3
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List4
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List5
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List6
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.list7
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.list8
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.list9
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List10
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
Set ctl = Me.List11
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
DoCmd.OpenForm "frmQual_Sub", acNormal, "lob IN(" & strWhere & ")"
Exit Sub
End Sub