Print Report from Subform Error

dkinnz

Registered User.
Local time
Today, 07:17
Joined
Jan 8, 2007
Messages
29
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 Date Between #01/01/2007# And #12/07/2007# and [TestField]='A')'.
It's not clear to me what i'm missing. Below is my code. 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 = "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
 
I would change the field named Date to something else. Date is a reserved term in Access (there is a function in Access Date()) so that could be a part of your problem.

Dave
 
Thanks for the reply but that doesnt seem to be the problem. I change the field name anyway just in case. Attached is my database if anyone would please take a closer look. I could really use some help with this as I've tried everything. Thank you!!
 
I think my database failed to attach in the last message, so here it is. I would really appreciate it if someone could please take a look at it and offer any insight as to what's going wrong. This is the final step in my database!
Thank you in advance!!
dkinnz
 

Attachments

Users who are viewing this thread

Back
Top Bottom