Changing Recordsources for a report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I have one form that, depending on where it is opened from, will have a specific query opened.

I want to do the same thing for a report, but am not having much success. I have tried this on the On_click event:
docmd.openreport "rptExpiredAgreement",acPreview,,me.recordsource = "qryReportExpiredAgreementArea"

I get a runtime error 2501. can anyone help me on this one?

Many thanks and happy christmas.

Carlee
 
I want to do the same thing for a
report, but am not having much success.
I have tried this on the On_click event:
docmd.openreport "rptExpiredAgreement",acPreview,,me.recordsource = "qryReportExpiredAgreementArea"

I get a runtime error 2501.

me.recordsource = "qryReportExpiredAgreementArea" is not valid syntax for
the WhereCondition clause... the WhereCondition, by definition, is to
contain a "WHERE clause without a WHERE".

Two options for doing what you want:

(1) create the report with a RecordSource of a Query without any Criteria or
Parameters, and use a valid DoCmd.OpenReport, with a "WHERE clause without
the WHERE" to filter the records

(2) Create the Query or SQL that you want to use, and in the Open event of
the report, use it to replace the RecordSource

Me.recordsource = "qryReportExpiredAgreementArea"

would work in this case, but from VBA code in the Report's Open Event.

Larry Linson
Microsoft Access MVP
 
Carle

Further to this subject, refer to the thread entitled

'report filtered form fails

Hope this helps, it did for m

Chops

----- Larry Linson wrote: ----

"Carlee" wrot
I want to do the same thing for
report, but am not having much success
I have tried this on the On_click event
docmd.openreport "rptExpiredAgreement",acPreview,,me.recordsource "qryReportExpiredAgreementArea

me.recordsource = "qryReportExpiredAgreementArea" is not valid syntax fo
the WhereCondition clause... the WhereCondition, by definition, is t
contain a "WHERE clause without a WHERE"

Two options for doing what you want

(1) create the report with a RecordSource of a Query without any Criteria o
Parameters, and use a valid DoCmd.OpenReport, with a "WHERE clause withou
the WHERE" to filter the record

(2) Create the Query or SQL that you want to use, and in the Open event o
the report, use it to replace the RecordSourc

Me.recordsource = "qryReportExpiredAgreementArea

would work in this case, but from VBA code in the Report's Open Event

Larry Linso
Microsoft Access MV
 
Back
Top