Print Report Error (1 Viewer)

dkinnz

Registered User.
Local time
Today, 08:09
Joined
Jan 8, 2007
Messages
29
Hello,
I have a user form with a date range and combo box filter. The user selected filtered results are displayed in a subform. I placed a print report button on the user form, but I'm getting the following error when the button is pressed:
Run-time error '3075': Syntax error (missing operator) in query expression '(Where Test Date Between #01/01/2007# And #12/07/2007# and [TestField]='A')'.
It's not clear to me what's wrong. Below is my code and attached is my database if anyone would like to have a look. Thank you for any help!!
Code:
Private Sub cmdPrint_Click()
 Dim stDocName As String
    Dim strCriteria As String

    strCriteria = FilterIt
      stDocName = "Test Report"
    DoCmd.OpenReport stDocName, acPreview, WhereCondition:=strCriteria
End Sub  

Private Function FilterIt() As Variant

Dim varFam As Variant
Dim strField As String
Dim strWhere As Variant
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strField = "Test Date"
strWhere = "1=1 "

If Me.cboTest <> "" Then
    varFam = varFam & "and [TestField]='" & Me.cboTest & "' "
End If

If IsNull(Me.txtStart) Then
        If Not IsNull(Me.txtEnd) Then   'End date, but no start.
            strWhere = strField & " <= " & Format(Me.txtEnd, conDateFormat)
        End If
Else
        If IsNull(Me.txtEnd) Then       'Start date, but no End.
            strWhere = strField & " >= " & Format(Me.txtStart, conDateFormat)
        Else                                'Both start and end dates.
            strWhere = strField & " Between " & Format(Me.txtStart, conDateFormat) _
                & " And " & Format(Me.txtEnd, conDateFormat)
        End If
End If

strWhere = strWhere & varFam
  FilterIt = "Where " & strWhere
 

Attachments

  • dbDate.zip
    35 KB · Views: 81

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:09
Joined
Aug 30, 2003
Messages
36,134
If you read help on the OpenReport wherecondition, it's a SQL WHERE clause without the word "where".
 

Users who are viewing this thread

Top Bottom