change report recordsource

  • Thread starter Thread starter smk23
  • Start date Start date
S

smk23

I would like to change a report's recordsource when certain criteria are met.
Currently my code looks like this:

DoCmd.OpenReport "rptProcSched", acViewPreview
Reports!rptProcSched.RecordSource = "qpAppointmentRequestCCDA"

But I get an error message that the recordsource cannot be changed in
preview view. When can it be changed? What's the best way to do this?
Thanks so much.

Sam
 
I would like to change a report's recordsource when certain criteria are met.
Currently my code looks like this:

DoCmd.OpenReport "rptProcSched", acViewPreview
Reports!rptProcSched.RecordSource = "qpAppointmentRequestCCDA"

But I get an error message that the recordsource cannot be changed in
preview view. When can it be changed? What's the best way to do this?
Thanks so much.

Sam



1) You could pass the recordsource query name to the report using the
OpenArgs argument:

DoCmd.OpenReport "rptProcSched", acViewPreview, , , ,
"qpAppointmentRequestCCDA"

Then, in the Report's Open event, code:

If Not IsNull(Me.OpenArgs) Then
Me.Recordsource = Me.OpenArgs
End If

or....
2) Just use the OpenReport's Filter argument instead:

DoCmd.OpenReport "rptProcSched", acViewPreview,
"qpAppointmentRequestCCDA"
 
Back
Top