Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the RecordSource in a Report

Status
Not open for further replies.

GGleason

Technical User
Mar 22, 2001
321
US
I have a form that when you click a command button, will tell an existing report to print. But I want to pass an SQL statement to the report’s record source before it prints so it prints exactly what I want.

When I try to do the following command:
[tt]
Application.Reports(“MyReport”).RecordSource = strSQL
[/tt]
I get the following error:

The report name ‘MyReport’ you entered is misspelled or refers to a report that isn’t open or doesn’t exist.

The SQL command I am sending is valid and the report does exist.

How can I set the record source for a report before I print it?

tia,
GGleason

 
It works when I place a statement to open the report in design first.

GGleason
 
You've stumbled on the secret - you can't change an objects recordsource (like a form or report) unless you open it in DESIGN view first and make the assignment, then you can open the object in "normal" view.

I've seen it done like this:

DoCmd.OpenFOrm XXXXX, acDesign
XXXXX.Recordsource = "sqlstring"
DoCmd.OpenForm XXXXX, acNormal






There are two ways to argue with a woman - neither one works.
Another free Access forum:
More Access stuff at
 
Yes, "stumbled" is the word. The error message helped me to understand that I needed to open the report before changing the RecordSource. Live and learn.

Thanks,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top