programmed parameter query in report

W

Wim

Hi all,

I want to generate a report from within VBA. The report
gets its records from a parameter query
(called "Results"), where the only parameter (as filled in
in the "criteria" field of the query) is :

[Give the starting date : ]

the code :

Set rst = db.OpenRecordset("Results", dbOpenDynaset)
DoCmd.OpenReport strReportName, acViewPreview, , ,
acWindowNormal
DoCmd.Close acReport, strReportName, acSaveNo

The error message is : "too few parameters. Expected 1"

Apparently I should be able to get the starting date from
a parameter input screen, but how ?

Thanks for helping,

Wim
 
M

Marshall Barton

Wim said:
I want to generate a report from within VBA. The report
gets its records from a parameter query
(called "Results"), where the only parameter (as filled in
in the "criteria" field of the query) is :

[Give the starting date : ]

the code :

Set rst = db.OpenRecordset("Results", dbOpenDynaset)
DoCmd.OpenReport strReportName, acViewPreview, , ,
acWindowNormal
DoCmd.Close acReport, strReportName, acSaveNo

The error message is : "too few parameters. Expected 1"

Apparently I should be able to get the starting date from
a parameter input screen, but how ?

The error message is coming from the OpenRecordset (the VBA
environment does not have access to the expression service
that is used to resolve parameters). In this situation,
don't worry about it because there is no reason to be
mucking about with a recordset. Also, it would be a bad
idea to Close the report before the user has had a chance to
view it (users will close it when they're done looking at
it). All you need is OpenReport line, so get rid of the
other two lines.
 
G

Guest

Thank you, I'll give it a try !
-----Original Message-----
Wim said:
I want to generate a report from within VBA. The report
gets its records from a parameter query
(called "Results"), where the only parameter (as filled in
in the "criteria" field of the query) is :

[Give the starting date : ]

the code :

Set rst = db.OpenRecordset("Results", dbOpenDynaset)
DoCmd.OpenReport strReportName, acViewPreview, , ,
acWindowNormal
DoCmd.Close acReport, strReportName, acSaveNo

The error message is : "too few parameters. Expected 1"

Apparently I should be able to get the starting date from
a parameter input screen, but how ?

The error message is coming from the OpenRecordset (the VBA
environment does not have access to the expression service
that is used to resolve parameters). In this situation,
don't worry about it because there is no reason to be
mucking about with a recordset. Also, it would be a bad
idea to Close the report before the user has had a chance to
view it (users will close it when they're done looking at
it). All you need is OpenReport line, so get rid of the
other two lines.
 

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