Calling report/setting Recordsource

  • Thread starter Thread starter Joao
  • Start date Start date
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?
 
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
 
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.
 
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
 
It worked Paolo! The only problem now is that I don't the report printed
everytime I call it!!!!
 
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!
 
Paolo, on the contrary, it prints everytime, but I found the simple solution:
It works like this:

DoCmd.OpenReport "ReportName", acPreview

Thanks anyway.
 
Back
Top