Changing Record Source for Report

R

rmcompute

I have a group of reports that I want to allow the user to print to Microsoft
Word programatically. In order to do this, I have to be able to dynamically
change the extraction criterion in the report. I am assuming with the
DoCmd.OutputTo command you cannot add extraction criterion, so I dynamically
created a query with this criterion and now have to dynamically change the
RecordSource property on the report. Is it possible to do that ? I tried:
Reports!rptBranchReport.RecordSource = qryBranchReport, but it said the
report had to be opened. Is there a way to accomplish this and then issue
the command below to extract the report to Microsoft Word ?

DoCmd.OutputTo acOutputReport, “rptBranchReportâ€, acFormatRTF,
“rptBranchReport.rtfâ€, False
 
M

Marshall Barton

rmcompute said:
I have a group of reports that I want to allow the user to print to Microsoft
Word programatically. In order to do this, I have to be able to dynamically
change the extraction criterion in the report. I am assuming with the
DoCmd.OutputTo command you cannot add extraction criterion, so I dynamically
created a query with this criterion and now have to dynamically change the
RecordSource property on the report. Is it possible to do that ? I tried:
Reports!rptBranchReport.RecordSource = qryBranchReport, but it said the
report had to be opened. Is there a way to accomplish this and then issue
the command below to extract the report to Microsoft Word ?

DoCmd.OutputTo acOutputReport, “rptBranchReport”, acFormatRTF,
“rptBranchReport.rtf”, False


I'm on very shakey ground here, but I think you can do this
by opening the report in previrew mode before using the
OutPutTo method. This way you can still use the
OpenReport's WhereCondition argument to filter the report.

If you really need to set the report's record source, you
can only do that reliably in the report's Open event. But
the report has to be opened for the events to execute so why
bother.
 
Top