I have a report based on a parameterized query, with the following a criteria on a date field:
“Between [Enter Begin date?] And [Enter End date?]“. No problem.
I am scheduling the report to be run automatically at a certain time a day, so I changed the parameter to
“Between datBDate() And Date()”
where datBDate is a function that calculates a specific Begin Date. Again no problem
But sometimes, the users still want to run the report interactively, and be able to enter any date range. How can I change the query, so it accepts both forms?
I tried to change the criteria to
IIf(bolAutoRun()=True,(([tblReceipt].[RecvDate]) Between datBDate() And Date()),(([tblReceipt].[RecvDate]) Between [Enter: From what date?] And [Enter: To what date?])).
The bolAutoRun() function returns “True” if the report is run automatically, and “False” if the report is run interactively, but it doesn’t work at all.
I also tried to use a function that returns a string based on bolAutoRun, either “Between [Enter: From what date?] And [Enter: To what date?]” or “Between datBDate() And Date()”, and just place that function into the criteria field, but it didn’t work (I didn’t expect it to, either, makes no sense, since it returns a string, not a date).
I saw a partial solution on The Access Web (http://home.att.net/~dashish/), to pass a parameter to a query via code (partial code snippet included):
Dim qdfParmQry As QueryDef ‘the actual query object
Set qdfParmQry = db.QueryDefs(“Qry1”)
qdfParmQry(“Please Enter Code:”) = 3
‘ or try this alternate method to pass the parameter
qdfParmQry![Please Enter City:] = “New York”
Set rs = qdfParmQry.OpenRecordset()
But I don’t know how to use this with my “Between” parameter, and I don’t know how to use this with a report, which is based on my query.
Any ideas? I’m all fresh out and sure could use some help.