several multi listbox issue

tmcrouse

Board Regular
Joined
Apr 10, 2012
Messages
121
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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top