Changing the Record Source

  • Thread starter Thread starter Treebeard
  • Start date Start date
T

Treebeard

Is there any way to print/preview a report with a different record source?

Thanks,

Jack
 
Me!MyReport.RecordSource = "OtherRecordSource"
DoCmd.OpenReport "MyReport" acPreview
 
It doesn't seem to work. I'm using Access 2000.

I'm running this report from a form's button OnClick event . If I use this:

Me!rptAccountMonthlyStatement.RecordSource = "qryInvoiceAgingReport"
DoCmd.OpenReport AccountMonthlyStatementReportName, acPreview

I get the following error message

"MS Access can't find the field referred to in your expression."
-----------------------------------------
If I Try this:

Reports!rptAccountMonthlyStatement.RecordSource = "qryInvoiceAgingReport"
DoCmd.OpenReport AccountMonthlyStatementReportName, acPreview

I get this error message:

The report name 'rptAccountMonthlyStatement' you entered is mispelled or
refers to a report that isn't open or doesn't exist.
---------------------------------------------------------------
If I Try this:

Report_rptAccountMonthlyStatement.RecordSource = "qryInvoiceAgingReport"
DoCmd.OpenReport AccountMonthlyStatementReportName, acPreview

I get this error message:

You can't set the record source property after the printing has started.
 
Jack,

There are a couple of ways to do this.

1. Set the recordsource in the Report_Open event of the
report:

Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = "<recordsource>"
End Sub

2. Use a base query in the report and specify a filter
and/or sort. The following code opens the report with the
same same filter and sort as a subform.

DoCmd.OpenReport "rptJobList", acViewPreview, , _
Nz(Me.JobListSubform.Form.Filter), , _
Nz(Me.JobListSubform.Form.OrderBy)

Hope this helps!

Tim
 
Jack,

Sorry, my mistake - I have a bad cold today and it's hard to think! Try this:

Put this code in the Click event of a button:

DoCmd.OpenReport "AccountMonthlyStatementReportName", acPreview

Put this code in the OnOpen event of the report:

Me.RecordSource = "qryInvoiceAgingReport"


Steve
PC Datasheet
 
Back
Top