title: Error 3131 when trying to query on multiselect list box
body: <p>I have a MultiSelect List Box that I'm trying to use as criteria in a query. I'm fine until the line of code "qdf.SQL = strSQL" at which point I receive the error code 3131.  If I place a message box just after the "strSQL =" command, it appears to populate with the correct data.</p>
  
  <p>I am pulling from a list of Categories on a form (Forms("frmMain").listCat1).</p>
  
  <p>What am I doing wrong?  Thank you in advance.  </p>
  
  <pre><code>Private Sub CAT1_Criteria()
  
  Dim varItem As Variant
  Dim strCAT1 As String
  Dim ctl As Control
  Dim strSQL As String
  
  Dim db As Database
  Dim qdf As QueryDef
  
  Set ctl = Forms("frmMain").listCat1
  
  For Each varItem In ctl.ItemsSelected
  strCAT1 = strCAT1 &amp; ",'" &amp; ctl.ItemData(varItem) _
  &amp; "'"
  Next varItem
  
  If Len(strCAT1) = 0 Then
  strCAT1 = "Like '*'"
  Else
  strCAT1 = Right(strCAT1, Len(strCAT1) - 1)
  strCAT1 = "IN(" &amp; strCAT1 &amp; ")"
  End If
  
  strSQL = "SELECT dbo_CATEGORY1.* FROM dbo_CATEGORY1" &amp; _
        "WHERE dbo_CATEGORY1.[LEVEL1] " &amp; strCAT1 &amp; ";"
  
  Set db = CurrentDb
  Set qdf = db.QueryDefs("qryCAT1_Sel")
  qdf.SQL = strSQL
  
  'Set qdf = Nothing
  'Set db = Nothing
  
  DoCmd.OpenQuery "qryCAT1_Sel"
  
  End Sub
  </code></pre>