Run stored query for report without displaying query

G

Guest

I have been trying to find a way to run a stored query for a report without
displaying the query. I've tried using the OpenRecordset method in VBA
without success. I would appreciate some direction.

The following code returns an error "To few parameters. Expected 1"

Dim db As Database
Dim strSQL As String
Dim rst As Recordset
Dim stDocName As String


Set db = CurrentDb
Set rst = db.OpenRecordset("CrReportQry")

stDocName = "Report1"
DoCmd.OpenReport stDocName, acViewPreview


Thanks,
Mike
 
G

Guest

Hi, Mike.

You don't need to open this query before opening the report.
DoCmd.OpenReport is the command to use. The report's Record Source Property
will grab the data from the appropriate query.

CrReportQry won't open because it "needs something" that isn't included in
the query's SQL statement. This may be a misspelled field name or a missing
table or query. To find out, try double-clicking on the query's name in the
Database Window to run the query. You'll likely be prompted for a parameter,
a specific field name. This field name isn't provided in the SQL statement,
so you need to fix this.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 

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

Similar Threads


Top