DoCmd Open form error on filter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lynch225
    New Member
    • Jan 2012
    • 43

    DoCmd Open form error on filter

    Hey all, everytime I open the form Clickform with a button, I keep getting a runtime error 3464- data type mismatch in criteria expression with the DoCmd line highlighted.

    Basically I have a group of checkboxes (Check1, Check2, etc.) on a form called Check, and the code filters through the checkboxes to see which ones are checked. Once the user clicks the button (called Command0), it opens up the Clickform and applies a filter based on the checkboxes. For instance, if Check3 and Check4 are highlighted, then the Checkform will be filtered on the records where Door=4 or Door=5. Here's my code:

    Code:
    Option Compare Database
    Option Base 1
    
    Private Sub Command0_Click()
    
    Dim Ctrl As Object, i, j, RecsChose, ThisChkbox, ErrMess, sqlStr, sqlPl
    Dim Narr() As Variant
    
    ThisChkbox = 0
    i = 0
    
    For Each Ctrl In Me.Controls
        If (Ctrl.ControlType = 106) Then
            ThisChkbox = Ctrl.Value
            If ThisChkbox Then
            i = i + 1
            ReDim Preserve Narr(i)
            Narr(i) = Ctrl.DefaultValue
            End If
        End If
    Next
    
    If i > 0 Then
        For j = 1 To UBound(Narr) - 1
            RecsChose = RecsChose & "Trailers_Unloading_LA.Door=" & Narr(j) & " OR "
        Next
        RecsChose = RecsChose & "Trailers_Unloading_LA.Door=" & Narr(j) & ";"
        sqlP1 = "SELECT Trailers_Unloading_LA.Door, Trailers_Unloading_LA.Trailer_Number, Trailers_Unloading_LA.LA01, Trailers_Unloading_LA.LA02, Trailers_Unloading_LA.LA03, Trailers_Unloading_LA.LA04, Trailers_Unloading_LA.LA05, Trailers_Unloading_LA.LA06, Trailers_Unloading_LA.LA07, Trailers_Unloading_LA.LA08, Trailers_Unloading_LA.LA09, Trailers_Unloading_LA.LA10 FROM Trailers_Unloading_LA WHERE "
        sqlStr = sqlP1 & RecsChose
        Else
        ErrMess = MsgBox("No trailers are being unloaded", vbOKOnly, "Status")
    End If
    
    Debug.Print sqlStr
    
    DoCmd.OpenForm "CheckForm", acNormal, sqlStr, , acFormReadOnly, acWindowNormal
    
    End Sub
    Any ideas why this is not working? I can't seem to figure it out after scouring the internet looking for reasons why it might not be working..
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Is Door a string? If so you need to surround the values in quotes.

    Comment

    • Lynch225
      New Member
      • Jan 2012
      • 43

      #3
      Ahhh yes, something so simple. Thanks rabbit.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Sure thing, good luck.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Ben, Here's a couple of links for you.
          1. Quotes (') and Double-Quotes (") - Where and When to use them
          2. When Posting (VBA or SQL) Code


          A should prove helpful with similar issues in future.
          B I would like (as a moderator) to ask you to read before posting code again. Never worry. You'll get much more from it than we will - it's a win-win for all. Using code with no Option Explicit line is just a recipe for problems for you.

          Comment

          Working...