Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenReport from within a module 1

Status
Not open for further replies.

WeyHey

IS-IT--Management
Feb 6, 2002
5
GB
I am trying to open a report using the DoCmd.OpenReport method and I want to use 2 variables of type date in the end where statement.

I have calculate the date range that I a using but cannot get the openreport to accept them as dates in the"WHERE" section of the call.

Is there a better way of doing this or do I need to specify a certain format in the "WHERE" section?

Cheers,

John.
 
You should copy/paste your line of code here, it would help
regards
 
The code I am using is below. Thanks,

John.

/*This takes todays date and works out a month range and then reports who using field DOB is going to be 18 soon. well it is supposed to anyway*/

dteRange1 = DateAdd("yyyy", -18, Date)
dteRange2 = DateAdd("m", 1, dteRange1)
DoCmd.OpenReport &quot;NAR_Under18&quot;, acViewPreview, &quot;pers dets qry NAR&quot;, &quot;DOB >= dteRange1 AND DOB <= dteRange2&quot;
 
Try copy/pasting this line, I removed the quotes around the variables and you need to use the format command.(See help on SQL criteria)
Also, I would avoid using spaces in object names.

DoCmd.OpenReport &quot;NAR_Under18&quot;, acViewPreview, &quot;pers dets qry NAR&quot;, &quot;DOB >=&quot; & format(dteRange1,&quot;yy/mm/dd&quot;) & &quot; AND DOB <= &quot; & format(dteRange2,&quot;yy/mm/dd&quot;)

 
If that doesn't work, try this:

DoCmd.OpenReport &quot;NAR_Under18&quot;, acViewPreview, &quot;pers dets qry NAR&quot;, &quot;DOB >= #&quot; & format(dteRange1,&quot;yy/mm/dd&quot;) & &quot;# AND DOB <= #&quot; & format(dteRange2,&quot;yy/mm/dd&quot;) & &quot;#&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top