setting a report's recordsource...

  • Thread starter Thread starter Brad Pears
  • Start date Start date
B

Brad Pears

I would like to set a reports record source when the report is not the
current object - menaing I can't use the "me.recordsource=" in the load
event (or whereever) of that object.

I want to set the property in code completely outside of the object...

What is the correct syntax to do this type of a thing?


Thanks,

Brad
 
You could pass the recordsource in openargs when you open the report.
I believe this was a new feature in Access 2003.

-Dorian
 
You have to have the report open in Design view to do this - once a
report is open in Print Preview mode you can't set the Recordsource.

To do this use the Reports collection - contains all open reports

Report("MyReportName").Recordsource="some recordsource".

This will have no effect until you do a Docmd.OpenReport in Preview or
Print mode - and if you don't want to change to be persistent, make
sure you close the report with the acSaveNo option (Docmd.Close).

Have you tried using the Filtername and WhereCondition arguments of the
OpenReport method?
Another way, if you need to set the Recordsource to something radically
different from its saved setting (so that using a Filter or Where won't
work), is to save the Recordsource string somewhere accessible - e.g.
in a textbox on an open form, in a Public member variable of an open
form - then the Report's Open event procedure can set
Me.Recordsource=Forms!AnOpenForm.mstrRptRecSource (variable), or
Forms!AnOpenForm!TxtRptRecSource (text box).

cheers


Seb
 
You cannot set the RecordSource of the reports in print preview or after
printing has started.

The last opportunity you have to set the RecordSource is in the Open event
of the report.
 
Back
Top