Date queries..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neosam
    New Member
    • Mar 2008
    • 47

    Date queries..

    Hi All,

    I want Access to open a report where the date is 3 days prior to today. Is this possible? I have written a code something like this :
    Code:
    DoCmd.OpenReport "ReportName", acViewPreview, , Date - 3
    Do I have to predefine the variable date or is it a system defined variable?
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    I believe that is pretty close to correct except Date needs to be Date() because it is a function that returns today's date, not a variable that holds it.

    Comment

    • neosam
      New Member
      • Mar 2008
      • 47

      #3
      Originally posted by janders468
      I believe that is pretty close to correct except Date needs to be Date() because it is a function that returns today's date, not a variable that holds it.
      When i do that.. the "()" disappears as soon as i move to the next line.... This is what i have been thinking about.....

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        The date function is a bit quirky that way - as it accepts no parameters the brackets disappear when you use it in expressions. As long as you don't have a local variable also called date (which would be a bad idea) the date will be returned correctly without the brackets, so Date - 3 is quite OK for referring to the date three days before the current one.

        -Stewart

        Comment

        • neosam
          New Member
          • Mar 2008
          • 47

          #5
          Originally posted by Stewart Ross Inverness
          The date function is a bit quirky that way - as it accepts no parameters the brackets disappear when you use it in expressions. As long as you don't have a local variable also called date (which would be a bad idea) the date will be returned correctly without the brackets, so Date - 3 is quite OK for referring to the date three days before the current one.

          -Stewart
          Thats what i had thought... but when i run it, i get a error message saying "Cant find object or Library" Do I have to reference some particular library for this case??

          Comment

          • janders468
            Recognized Expert New Member
            • Mar 2008
            • 112

            #6
            I was a bit misleading without the parens is fine I thought you were running it as a query not in VBA. I don't believe the error is referring to the date function but probably to the report name ("ReportName " in your above code). Is there a report named "ReportName " in your database, or rather, is there a report named whatever you have plugged into your code in your database? That would be my first guess, if you want, paste your code if it is different from your original post

            Comment

            Working...