change report recordsource

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
 
F

fredg

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"
 

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