Full Version: How to change the Record Source before preview?
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
sunfire4jc
Hello

My report record source is genreated by the users selection of which items they want on teh report. I put a button to "preview report" before they print.Any ideas on how to change the record source before the print preview screen comes up?

How do you use the VBA to reference the recordsource of the report when you are on a different form?

i currently have this as the VBA,

CODE
  Reports![reportquery].RecordSource = reportSQL


it runs when i use it as a query, but i get an error saying that "the referenced report is mispelled/does not exist" which is weird cuz when i comment out the line, the report runs fine

When i put my sql code into the "on open" event in the report, it says that "You cannot change the record source during a print preview"

Any ideas?

Let me know,
Thanks

Edited by: sunfire4jc on Thu Aug 11 23:55:00 GMT-5 2005.
narbspot
You can only set the record source propert in Design View. If you generate your own recordsource for the Report

First:

DoCmd.OpenReport "Your Report", acViewDesign

Then Assign RecordSource:
Reports!YourReport!RecordSource = yourRecordSource


Then Change View to Print Preview:

DoCmd.OpenReprot "Your Report", acViewPreview


Hope this helps.
khaos
You can change the recordsource of a report in the on open event. There is no reason for narbspot's code. Since you have 2002 you can use the openargs property, not available before 2002 for reports. I use this to supply a source to a report. Try this

docmd.OpenReport "rptName",acViewDesign,,,,"sqryWhatever"

to open the report, in the on open event use

if not isNull(me.openargs) then
me.recordsource=me.openargs
else
'do something else, cancel report or use default source, it's up to you
end if

HTH
Ken
narbspot
Didn't even look at his Access Version...go point.
khaos
Version doesn't matter, it's just a lot easier with 2002. Before you could use custom properties or global variables. Of course even without that you can always set the source of a form or report in the on open event.

Ken
narbspot
I learn something new everyday here...You are a bright one Ken
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.