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:
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..
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
Comment