Calling report/setting Recordsource

J

Joao

I want to open a Report using this:

SQLString = "Select * from table"

Code:
Reports!Report1.RecordSource = SQLString
DoCmd.OpenReport "Report1", acViewNormal, , , acWindowNormal

The error says the report name is misspelled or doesn't exist...
I am sure my report is named Report1...
Anyone? Other solution?
 
P

Paolo

Hi Joao,
actually to manipulate the recordsource of a report the report must be
already open and in your case you first assign the recordsource to something
that still doesn't exist and then you open it.
To make it work you must first open the report with the docmd.openreport
command and then you can assign the recordsource in the on open event of the
report.
I don't understand why you don't assign the recordsource in design mode of
the report, 'cause if you use something to filter I can understand the
meaning to assign the recordsource dynamically but in this case you assign
just a table as recordsource and so you can do it at design mode.

HTH Paolo
 
J

Joao

Thanks Paolo, i will try your tip. That simple SQL was just an example... The
SQL I intend to put dinamically is much more complex.
 
P

Paolo

Well Joao,
if the source table remains the same and you wanna change the parameters you
can pass them in the docmd.openreport "yourreport,,whereconditions
If you need to change also the table/query on which is based the report you
have to change it in the open event of the report as I said before.

Regards Paolo
 
J

Joao

It worked Paolo! The only problem now is that I don't the report printed
everytime I call it!!!!
 
P

Paolo

It doesn't print everytime you call it? So it doesn't work very well!
If you post the code I can try to understand why!
 
J

Joao

Paolo, on the contrary, it prints everytime, but I found the simple solution:
It works like this:

DoCmd.OpenReport "ReportName", acPreview

Thanks anyway.
 

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