Connecting Tech Pros Worldwide Help | Site Map

Date queries..

Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47
#1: Jun 26 '08
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 :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "ReportName", acViewPreview, , Date - 3
  2.  
Do I have to predefine the variable date or is it a system defined variable?
Expert
 
Join Date: Mar 2008
Location: Firestone, CO
Posts: 112
#2: Jun 26 '08

re: Date queries..


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.
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47
#3: Jun 27 '08

re: Date queries..


Quote:

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.....
Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#4: Jun 27 '08

re: Date queries..


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
Member
 
Join Date: Mar 2008
Location: Bangalore, India
Posts: 47
#5: Jun 27 '08

re: Date queries..


Quote:

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??
Expert
 
Join Date: Mar 2008
Location: Firestone, CO
Posts: 112
#6: Jun 27 '08

re: Date queries..


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
Reply


Similar Microsoft Access / VBA bytes