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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cancel report printing if a calculation fails ?

Status
Not open for further replies.

NeutralPoint

Programmer
Oct 3, 2002
3
FR
Hi all,

In Access 97, I need to cancel a report printing if a calculated control (edit text one) fails to be calculated. How to do-it ?

My current state:
-----------------
A report called from a form through a "DoCmd.OpenReport strReportName, acNormal, , strLinkCriteria".

In the report, a control called "AddressCtrl" with its SourceControl as "=DefAddress()" and a DefAddress() function which set a global flag like "bAbortReport=True" if the address calculation fails to be completed.

From this point, where to use the bAbortReport flag ?

I've tried to place a "If bAbortReport=True THEN Cancel=True" in the OnFormat and OnPrint events of the concerned section (the calculated field is in a GroupHeader section) but the events happens before the field calculation (ie. internal call to DefAddress()). I've tried using the OnPage event of the report, but there's no Cancel parameter to manage, prior to effective printing.

Well, do you have an idea ? What's the point I've missed ?

Cordially
Eric
 
What about testing whether the calculated control will work before calling the openreport function.

e.g. you should be able to test the function on the query which underlies the report or even create a query that includes the function

Just an idea but perhaps I'm missing something

Andy

 
Thanks for the ideas Andy, but two constraints forgottent in my description :

- I launch a MsgBox to warn user if the textbox fails to be calculated => If I manage the query on which the report is based to be empty (with no record), I'll just get possibility to detect the NoData event, but not any way (I believe) to display an accurate warning about this specific textbox.

Well, however, it pushes an idea in my mind : could I change the report's SourceControl on the fly, after my msgbox and before printing, to do it points toward a bogus-query which will returns no data (this because I've read that a SourceControl="" will not fires the NoData event).

About your other solution to check the calculation prior to call (ie. in the form's module), It will do things will be calculated twice... And report's working tighly dependent of the form and it's command ; knowing this same report can be called from several forms (of course, I could place this code like PreChecking() function in an independent module, but I would prefer a solution where all report stuffs stay with the report itself). Just a first and quick feeling (maybe a wrong one).

Eric
 
Problem solved !

Here is a quick summary about the way I've finally used :

- Behind a Cmd_Print button in the form, I call a PrepReport() function which calculates and validates some hidden textbox controls.

- If PrepReport() fails, I warn user about the specific reason why and don't engage the printing. If all sounds right, I launch the report which is based on a query which gathers some info from several tables and the content of the hidden (on screen) calculated controls previously computed.

- Of course, and to complete toward a nice behavior, things are done in report to manage the NoData event case with a "Cancel=True" inside its fonction handler ; since query may return a zero record result even if calculated controls are corrects.

At this time all sounds right.
Cordially
Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top