pass parameter to a report

0

00eric claption

I put a parameter in select query and create a report which recordsource is
this query. Also write in code as the following suggested, but when I run
the following code. It keeps asking me the parameter value in the query even
after I set the theparametervalue = constant. Please help. THanks.


John Vinson said:
OK. In coding, what is the syntax to pass the parameter to the query and
how to run the report with passed parameter? Thanks.

What's the context, Eric? Where is the parameter coming from?

One thing you could do, if the parameter is available within VBA but
not (readily) on a Form or other source, is actually construct the
Report's SQL string in code and set its Recordsource property to the
string.

Or, use the WhereCondition parameter of OpenReport:

Dim strSQL As String
strSQL = "[fieldname] = " & TheParameterValue
DoCmd.OpenReport "rptMyReport", WhereCondition := strSQL

John W. Vinson[MVP]
 
M

Michel Walsh

Hi,


The proposed code seems to be about a criteria, while it seems you need an
assignation. Both use the same symbol, =, but 4= 2+2 is not the same as
x=4, as in put 4 in x, not as in is x equals to 4.


For a report, you can modify the report recordsource in the open event
handling procedure, or, maybe easier, you can use a syntax like

FORMS!formNameHere!ControlNameHere


as parameter, to specify a value to be used in the recordset over which will
operate the report.


It is preferable to continue on the same "discussion thread" rather than
starting a new one, since then people will know what has already been
discussed. Actually, not knowing that, we may end to REPEAT what has already
been said because *I* don't know what has been said, already. And thus, that
may be more a pain for you to fell you start all over again in describing
your problem.



Hoping it may help,
Vanderghast, Access MVP



00eric claption said:
I put a parameter in select query and create a report which recordsource is
this query. Also write in code as the following suggested, but when I run
the following code. It keeps asking me the parameter value in the query
even
after I set the theparametervalue = constant. Please help. THanks.


John Vinson said:
OK. In coding, what is the syntax to pass the parameter to the query and
how to run the report with passed parameter? Thanks.

What's the context, Eric? Where is the parameter coming from?

One thing you could do, if the parameter is available within VBA but
not (readily) on a Form or other source, is actually construct the
Report's SQL string in code and set its Recordsource property to the
string.

Or, use the WhereCondition parameter of OpenReport:

Dim strSQL As String
strSQL = "[fieldname] = " & TheParameterValue
DoCmd.OpenReport "rptMyReport", WhereCondition := strSQL

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top