Results 1 to 6 of 6
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    error 3071 on OpenReport command

    I have a form with three text boxes (one is for text and the other two are for dates) which are used to filter a report. I run the report via the following command but I get an error 3071:

    DoCmd.OpenReport "CollectionInvoices", acViewPreview, , "Company = '" & _


    Me.CompanyNameText & "' And InvoiceDate >= '" & Me.StartDateText & _
    "' And InvoiceDate <= '" & Me.EndDateText & "'"

    From Access help:
    This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to variables. (Error 3071)

    Should I be using the "Between" function (syntax) ?

    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If InvoiceDate is a date/time field, the values need to be surrounded by # rather than '.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    DoCmd.OpenReport "CollectionInvoices", acViewPreview, , "Company = " & _
    Me.CompanyNameText & And "InvoiceDate >= " & #Me.StartDateText# & _
    And "InvoiceDate <= " & #Me.EndDateText#

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by NTC View Post
    DoCmd.OpenReport "CollectionInvoices", acViewPreview, , "Company = " & _
    Me.CompanyNameText & And "InvoiceDate >= " & #Me.StartDateText# & _
    And "InvoiceDate <= " & #Me.EndDateText#
    That won't even compile.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Thanks. This did the trick:

    DoCmd.OpenReport "CollectionInvoices", acViewPreview, , "Company = '" & _
    Me.CompanyNameText & "' And InvoiceDate >= #" & Me.StartDateText & _
    "# And InvoiceDate <= #" & Me.EndDateText & "#"

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  3. Microsoft Access Error 3071
    By Ev0luTioN in forum Access
    Replies: 1
    Last Post: 08-04-2010, 04:35 PM
  4. OpenReport Command with Double Check Where Statement
    By Robert M in forum Programming
    Replies: 3
    Last Post: 09-17-2009, 04:01 PM
  5. Replies: 0
    Last Post: 09-11-2006, 07:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums