I am attempting to create a form that allows a user to open a flexible report by offering several search criteria options in the form of checkboxes with corresponding textboxes. I am using 4 checkbox/textbox options and 1 checkbox/datefield option (i'm using a between date expression). I am getting an error when any of the textbox options are selected and the datefield option is not selected - the syntax error states there is an error in date in my query expression:
"Syntax error in date in query expression '(Client like '*honda*' AND Assignee like '**' AND Inventor like '**' AND Title like '**' AND date_created Between ## AND ##'."
I got the code to start my cmd buttom from Tek-Tips, so I thought I could possibly get some help for what I am doing wrong. Am I missing a quote or apostrophe somewhere with my "strWhere=" expression? Here is my code:
Dim strWhere As String 'String variable to store where clause
"Syntax error in date in query expression '(Client like '*honda*' AND Assignee like '**' AND Inventor like '**' AND Title like '**' AND date_created Between ## AND ##'."
I got the code to start my cmd buttom from Tek-Tips, so I thought I could possibly get some help for what I am doing wrong. Am I missing a quote or apostrophe somewhere with my "strWhere=" expression? Here is my code:
Dim strWhere As String 'String variable to store where clause
Code:
If (Me.chkClient = True And Len(Me.txtClient & "") > 0) Or (Me.chkAssignee = True And Len(Me.txtAssignee & "") > 0) Or (Me.chkInventor = True And Len(Me.txtInventor & "") > 0) Or (Me.chkTitle = True And Len(Me.txtTitle & "") > 0) Or (Me.chkCreatedDate = True And (Len(Me.txtCreatedDate1 & "") > 0 And Len(Me.txtCreatedDate2 & "") > 0)) Then
'search criteria is valid: checkbox selected and corresponding textbox value is present for either of the search options on the form.
strWhere = strWhere & " AND Client like '" & "*" & Me.txtClient & "*" & "' AND Assignee like '" & "*" & Me.txtAssignee & "*" & "'AND Inventor like '" & "*" & Me.txtInventor & "*" & "' AND Title like '" & "*" & Me.txtTitle & "*" & "'" & " AND date_created Between #" & Me.txtCreatedDate1 & "# AND #" & Me.txtCreatedDate2 & "#"
End If
If Len(strWhere & "") = 0 Then
' checkbox not selected and/or corresponding textbox is not valid . Return message box informing of "Invalid Search Criteria".
MsgBox "Please confirm search criteria.", vbInformation, "Invalid Search Criteria"
Else
' remove first "AND" from where condition and pass across to report
DoCmd.OpenReport "Report2", acViewPreview, WhereCondition:=Mid(strWhere, 6)
End If