Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancel Event on NO DATA Event 2

Status
Not open for further replies.

GShen

MIS
Sep 26, 2002
561
US
I am trying to cancel a report if there is no data. I put in some VB code for DoCmd.CancelEvent which works when you are running the report manually. However, I am running this through a loop in VB. I basically create a recordset of everyone who gets the report and loop through it. I did not want to print reports which did not have any data because it is printing custom labels. When it tries to open the report in the loop, I get an error
THE OPEN REPORT ACTION WAS CANCELLED. Can I somehow suppress this from popping up for this 1 report or is there another way of getting around this. I was going to do a dlookup and see if there are any records to print but the WHERE condition on this is very intense plus it is just more unnecessary overhead.
Thanks.

Remember when... everything worked and there was a reason for it?
 
As far as I recall, the error is 2501. This can be trapped in an error trap.
 
You would need to handle the 2501 error in the "running this through a loop in VB". The error is generated in the code that opens the report rather than in the report itself.

Duane
Hook'D on Access
MS Access MVP
 
Okay,
I tried trapping the error in VB using Remou's tech with ON Error. For some reason it was still prompting me. Then I reran again and it worked the 1st time through and then stopped. I then put in the Resume Next and it seems everything is fine..... for now. So to sum up, I did the Docmd.CancelEvent on the report. Use the On Error in the VB code in the routine which calls for the report and Checked for "2501" in the error routine and performed a Resume Next when it was true (eg. 2501).

Thanks everyone for your help.

Remember when... everything worked and there was a reason for it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top