I have created a report, and set the record source to a parameterized query. The query has two parameters, DATEFROM, and DATETO. Although uncommon, I want to maintain the ability for a user to directly open the report using the DB Window at which point, Access will naturally ask the user to enter "DATEFROM" and "DATETO".
However, most common users will go through a form to open the report; at which point I don't want the application to prompt them to enter DATEFROM and DATETO
Despite everything I try, including the code below, Access still prompts me to enter the parameters DATEFROM and DATETO. Does anybody know why the code might not work when attached to a report?
P.S. Yes, I'm aware that I can change teh saved query to [Forms]![MyForm]!txtDate.Value, but that defeats my goal of report atonomy as mentioned in the first paragraph. I am more interested to know why I can't set a querydef parameter in VB and not have Access recognize it.
However, most common users will go through a form to open the report; at which point I don't want the application to prompt them to enter DATEFROM and DATETO
Despite everything I try, including the code below, Access still prompts me to enter the parameters DATEFROM and DATETO. Does anybody know why the code might not work when attached to a report?
Code:
Dim qDef As QueryDef
Set qDef = CurrentDb.QueryDefs("qryReport")
qDef.Parameters("DATEFROM") = DateAdd("d", -75, txtDate.Value)
qDef.Parameters("DATETO") = txtDate.Value
DoCmd.OpenReport "rptUsage", acViewPreview
P.S. Yes, I'm aware that I can change teh saved query to [Forms]![MyForm]!txtDate.Value, but that defeats my goal of report atonomy as mentioned in the first paragraph. I am more interested to know why I can't set a querydef parameter in VB and not have Access recognize it.
Last edited: