How to cancel a report running

thetallblokethetallbloke Member Posts: 66
Hi Guys,

I have built a new report and added controls to the Request form to take in some values to filter the data in the report.

I want to force the user to enter/select a value in each of the 2 controls I've added.

At the moment I have the following code in the OnPreReport trigger:
IF gRun = '' THEN BEGIN
  ERROR('You must select a "Run/Transport No" value');
END;

This along with the other IF statement I have does the job, sort of. This closes the Request form.

Is there a way to stop processing the report, display a message to the user and redisplay the Request Form to the user..??? until they get it right or hit the Cancel button in frustration :wink:

Thanks
.
I'm not crazy !!! Just ask my toaster...
.

Comments

  • krikikriki Member, Moderator Posts: 9,110
    You might try the "OnQueryCloseForm()"-trigger of the requestform.
    Test your fields there and until they give a value, you can exit(FALSE) (Never tried it though).

    The other way is the way you are using.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • thetallblokethetallbloke Member Posts: 66
    Thanks Alain...

    It didn't work unfortunately.. The report runs anyway with no criteria and then I get my Error messages at the end...
    .
    I'm not crazy !!! Just ask my toaster...
    .
  • rthswrthsw Member Posts: 73
    Make a DIALOG or a Form, and ask there for all of the parameters. On hitting OK, test the inputs about your needs. if everything OK, run the report w/o Requestform. If the options don't hit your needs, just give an Message, and Navi will stay in the form.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    Try Writing following code in 'OnPreDataItem()' of the first dataItem of the Report. :-k



    IF gRun = '' THEN BEGIN
    message('You must select a "Run/Transport No" value');
    CurrReport.QUIT;
    REPORT.RUN(ID of the current Report);
    END;
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • warraxwarrax Member Posts: 25
    kriki wrote:
    You might try the "OnQueryCloseForm()"-trigger of the requestform.
    Test your fields there and until they give a value, you can exit(FALSE) (Never tried it though).

    The other way is the way you are using.

    This won't work - The RequestForm only closes once the report has finshed running, not when you click on the "Print"/"Preview" buttons.
  • DenSterDenSter Member Posts: 8,305
    I think I know what you mean. You want to give the user an error, but you don't want the report to close completely. The OnPreReport trigger is too late for that, because it doesn't run until after the request form is closed.

    I've done this by putting the textbox to enter that number on the options tab, so then you can program in OnAfterValidate of the request form. You can still program an ERROR, but it will put you back into the request form.
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    DenSter wrote:
    The OnPreReport trigger is too late for that, because it doesn't run until after the request form is closed.

    I believe, Request form gets closed after the execution of OnPostReport trigger and hence after OnPreReport trigger too. :-k
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
  • DenSterDenSter Member Posts: 8,305
    I believe, Request form gets closed after the execution of OnPostReport trigger and hence after OnPreReport trigger too. :-k
    That is not correct.

    The Request form is closed before the OnPreReport trigger runs. It has to, because OnPreReport uses values that are entered into the request form.

    The order of report triggers:
    OnInitReport
    enter values in Request form (dataitem tabs and options tab)
    close request form (Click OK, print or print preview, cancel just closes it down)
    OnPreReport
    then it starts working through the dataitems
    OnPostReport
  • Sandeep_PrajapatiSandeep_Prajapati Member Posts: 151
    I believe, Request form gets closed after the execution of OnPostReport trigger and hence after OnPreReport trigger too. :-k
    DenSter wrote:
    The Request form is closed before the OnPreReport trigger runs. It has to, because OnPreReport uses values that are entered into the request form.


    I did the following exercise.

    a) Created a simple report with an option form (with a control on it) , one DataItem - Integer with MaxIteration = 1
    b) Declared a global variable "i" of datatype integer in the report.
    c) put a message with (after) incrementing "i" in some of the triggers as follows....


    1)Integer - OnOpenForm()
    i := i + 1;
    MESSAGE( 'Integer - OnOpenForm() - %1',i);

    2)Integer - OnCloseForm()
    i := i + 1;
    MESSAGE( 'Integer - OnCloseForm() - %1',i);

    3)Report - OnPreReport()
    i := i + 1;
    MESSAGE( 'Report - OnPreReport() - %1',i);

    4)Report - OnPostReport()
    i := i + 1;
    MESSAGE( 'Report - OnPostReport() - %1',i);

    5)Integer - OnPreDataItem()
    i := i + 1;
    MESSAGE( 'Report - OnPreDataItem() - %1',i);

    6)Integer - OnAfterGetRecord()
    i := i + 1;
    MESSAGE( 'Integer - OnAfterGetRecord() - %1',i);


    When running the report I got the messages as .....


    Integer - OnOpenForm() - 1
    Report - OnPreReport() - 2
    Integer - OnPreDataItem() - 3
    Integer - OnAfterGetRecord() - 4
    Report - OnPostReport() - 5
    Integer - OncloseForm() - 6




    So If there is nothing involved that I have ignored in my thought process, the above mentioned messages order is the order of their execution and implies that the option form only dissapears and is out of focus but is not closed before OnPostReport() trigger. :-k
    Sandeep Prajapati
    Technical Consultant, MS Dynamics NAV
Sign In or Register to comment.