Changing the Record Source

T

Treebeard

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

Thanks,

Jack
 
P

PC Datasheet

Me!MyReport.RecordSource = "OtherRecordSource"
DoCmd.OpenReport "MyReport" acPreview
 
T

Treebeard

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.
 
T

Tim

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
 
P

PC Datasheet

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top