DoCmd.OpenReport with date criteria generating Runtime error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rwonggnb
    New Member
    • Mar 2015
    • 1

    #1

    DoCmd.OpenReport with date criteria generating Runtime error

    Hi, I have a table with a DateTime field [Entry Date] and a form where a user enters a date and hits a "submit" button to open a report that should only display entries whose dates match the user entry. When I run this line of code to open the report:

    DoCmd.OpenRepor t "All Employee Daily Report 2", acViewReport, , "[Entry Date] = " & Format(Me.txtDa te, "\#mm\/dd\/yyyy\#")

    I get this error:
    Run-time error '102':
    Incorrect syntax near '#'

    Can someone help me out? I was under the impression that dates have to be enclosed in '#' so i'm not sure what's the problem.
  • Brilstern
    New Member
    • Dec 2011
    • 208

    #2
    I believe you would only use # when you are enclosing an actual date. Try this.

    Code:
    Dim strValue as String
    
    strValue = "#" & Me.txtDate & "#"
    DoCmd.OpenReport "All Employee Daily Report 2", acViewReport, , "[Entry Date] = " & Format(strValue, "mm/dd/yyyy")
    This is just a shot in the dark, haven't tested it yet.

    Comment

    • MikeTheBike
      Recognized Expert Contributor
      • Jun 2007
      • 640

      #3
      Hi

      I always use
      Code:
      DoCmd.OpenReport "All Employee Daily Report 2", acViewReport, , "[Entry Date] = #" & Format(Me.txtDate, "mm/dd/yyyy") & "#"
      ??

      MTB

      Comment

      Working...