views:

152

answers:

1

We need to make a Crystal Report pop up a custom error message and then stop running. Numerous Google searches have not even found anyone else asking how to do this before.

(The error is triggered to prevent the user from accidentally making a long running query that pegs the CPU on the database server. The report has no parameters, the third-party software appends filter criteria to the record selection formula.)

The best we have so far is:

NumberVar Zero := 0;

if InStr (RecordSelection, "IndexField", 1) <> 0 
then 1
else 1/Zero // Force divide by zero error to stop report from running

This successfully halts the report, but displays the users the confusing "Divide by zero" error rather than an informative error message.

If we can't get an entirely custom error message, being able to customize part of the message might be an acceptable substitute.

The Crystal Report is run by a third party application, so we have to be able to trigger it entirely from within Crystal. We are using Crystal Reports Professional version 11.0.0.895.

I don't think the effort of writing a Crystal function library and deploying it to everywhere this runs is worth it, so this needs to be done using built-in Crystal functionality or other standard features available everywhere.

A: 

If I'm understanding you correctly, you don't want to run the query if there are no filter parameters.

I don't think there's an easy way to create a custom pop-up, but I wonder if you could move the actual report data to a subreport and leave the main report blank. In the suppression formula for the subreport, you could put InStr (RecordSelection, "IndexField", 1) = 0. Suppressed subreports don't execute, so your long running query would have no effect. In a separate section, you could put a textbox with your error message in it. The suppression formula for that section would be InStr (RecordSelection, "IndexField", 1) <> 0.

The users wouldn't get a popup, but there would be a message on the report itself as to why it failed.

Graham
Hmm, that idea has potential. I'll have to see if we can pass the entire recordselection down from the main report and use that as the recordselection for the subreport.
LeBleu