On no data open a different report

  • Thread starter Thread starter Anne
  • Start date Start date
A

Anne

I am working with certified payroll reports and a report needs to be
generated for each week, even if there is no data.
The report which does have data, has an on format event, which numbers the
pages per job.
I need to create the report, even is there is no data, showing the company
info, the week ending data and week number and a label which displays that
there is not data for that week. In order to accomplish that, I had to
create a different query based on the job, which has the company data and
the info required and with that a 2nd report, which is based on that query.

I am using an or error event of the first report, to trap the error when it
is looking for the job numer which does not exists. Right now, the on error
handler is as follows: DoCmd.OpenReport "6-Any Week Certified
payrollNoData", acViewPreview
It works, but I got both the first reports show #ERROR in each field and the
2nd report showing the correct data.

How can I closed the first report and open the 2nd report?

Perhaps, I need to catch the no data event some where else?
Thanks,
Anne
 
A report has a NoData event that you can use. This does not require you to
trap an error. The event will fire when the report has no data. You could
open the other report in this event and close the first report. To close the
first report, set Cancel = True in its NoData event. This may cause a 2501
error in the code that opened the first report. If so, just trap the 2501
error in the code that opened the first report. The error is simply
complaining that the report it tried to open was Cancelled, which is
correct, it was, because you told it to cancel.
 
Yes this works.
I went back and let the first report go to the no data event and set it to
cancel = true
then the DoCmd.OpenReport did the job perfectly.
Thanks,
Anne
 

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

Back
Top