aidmang 0 Newbie Poster

Hi,

I have a successful multi list box working for 2 parameters in my Access Query. However the issue is that if I select 3 items in the first list box and 1 item in the second list box the Query structure is incorrect in that 2 items are at the "criteria" line from list box 1 and 1 item is on the "or" line from list box 1 together with the one item from list box 2.

I really need the 3 items from list box 1 and the 1 item from list box 2 all showing on the "criteria" line in order for the filtering to work correctly.
Hope you understand my problem.

Here is my code

Private Sub cmdOpenQuery_Click()

 On Error GoTo Err_cmdOpenQuery_Click

   Dim db As DAO.Database
   Dim qdf As DAO.QueryDef
   
   Dim varItem As Variant
   Dim strCriteria As String
   
   Dim varItem1 As Variant
   Dim strCriteria1 As String
   
   Dim strSQL As String
   Set db = CurrentDb()
   Set qdf = db.QueryDefs("Q_Filtered_parameters")
   
   
   If Me!Batch.ItemsSelected.Count > 0 Then
      'For Each varItem In Me!Batch.ItemsSelected
         strCriteria = strCriteria & "batch = " & Chr(34) _
                       & Me!Batch.ItemData(varItem) & Chr(34) & "OR "
      'Next varItem
      'strCriteria = Left(strCriteria, Len(strCriteria) - 3)
            
   Else
     strCriteria = "batch Like '*'"
   End If
     
   
   If Me!Week.ItemsSelected.Count > 0 Then
      For Each varItem1 In Me!Week.ItemsSelected
         strCriteria1 = strCriteria1 & "week = " & Chr(34) _
                       & Me!Week.ItemData(varItem1) & Chr(34) & "OR "
      
  Next varItem1
      strCriteria1 = Left(strCriteria1, Len(strCriteria1) - 3)
   Else
      strCriteria1 = "week Like '*'"
   End If
   
   strSQL = "SELECT * FROM T_DT_summary_of_appended_faults_GKF_L5 " & _
            "WHERE " & strCriteria & "AND " & strCriteria1 & ";"
            
   qdf.SQL = strSQL
   DoCmd.OpenQuery "Q_Filtered_parameters"
   Set db = Nothing
   Set qdf = Nothing


Exit_cmdOpenQuery_Click:
    Exit Sub

Err_cmdOpenQuery_Click:
    MsgBox Err.Description
    Resume Exit_cmdOpenQuery_Click
  
End Sub