Report OnFormat - cancel print

I need to cancel a report print when I get an error in the OnFormat section of the report.  The particular error is 2100 "The control or subform control is too large for this location."
Any help greately appreciated
Many thanks
D THomas
David ThomasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
I've never tried to cancel a report that was that far in (usually you do it in the OnOpen or NoData events), but try a simple:

   DoCmd.Close acReport,

 and see if it works.

If not, then this should work:

1. Declare a variable in the report modules declaration section:

Dim bolCancelReport as boolean.

2. In your OnFormat error handler, do:

   bolCancelReport = True

3. In the same OnFormat section, do:

If bolCancelReport = True then
 Me.PrintSection = False
 Me.NextRecord = True
 Me.Movelayout = False
End If

4. For any remaining sections, you may need to do:

 Me.PrintSection = False
 Me.Movelayout = False

This will in effect skip through the remaining part of the report until it completes.

David ThomasAuthor Commented:
Thank you for the speedy response Jim I will give that a try and let you know.
David ThomasAuthor Commented:
Hi again Jim, I tried your code and thanks again but I could not get it to do the job (probably my fault) so I've used another approach.  The code is printing labels where my application sets up the position of each field on the report dynamically as the user decides.  It is possible, even using the guidance I provide, the user will set a field to go outside the print area and get the error message to this effect.  I have now suppressed the message and send a single label to print for the user to confirm before the full quantity is printed.

Thanks again,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
OK.   Make sure you select your last comment as the answer.

David ThomasAuthor Commented:
I needed a quick resolution so I used a different approch to resolve it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.