Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Cancel a Report in Auto Search

edited May 2009 in General
I am using the OnGetAutoSearchValues event to set the Search Expression.
The ShowAutoSearchDialog property is set to false.

I want to be able to cancel the printing of the report under certain
conditions. The message is displayed but the report is still shown
despite using the statement TppReport(Sender).Cancel.

(The DeviceType is Screen).

How can I cancel the report in this situation?



procedure TfmUserReports.ppReport1GetAutoSearchValues(Sender: TObject);

begin
lAutoSearchField := ppReport1.AutoSearchFieldByName('JobID');
if Assigned(lAutoSearchField) then
begin
lAutoSearchField.SearchExpression :=
dmData.qyJobsForContact.FieldByName('ID').AsString;
end else
begin
MessageDlg('A Contact has not been selected', mtWarning, [mbOK], 0);
TppReport(Sender).Cancel;
end;
end;

Richard Harding

Comments

  • edited May 2009
    Hi Richard,

    The print process has already begun once the OnGetAutoSearchValues event
    fires therefore it is too late to cancel the report. The latest event to
    cancel the report during generation is the OnInitializeParameters event.

    Looking at your code however you are simply checking for the existance of
    the autosearch field rather than a search value. If you would like to make
    a search value mandatory, you can set the Mandatory property of the
    AutoSearch field to true and the user then will be required to enter a value
    to continue.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.