Stop form closing

Debbie140Debbie140 Member Posts: 52
edited 2004-07-23 in Navision Attain
Is there a way to force a form to stay open if someone clicks the close button and a condition is not true. For example if I checked for a condition of the onClose trigger of the form can I then say if this is not true then keep the form open.

Comments

  • StephenGStephenG Member Posts: 99
    Hi Debbie


    You can use the OnQueryCloseForm trigger.

    Online Help
    The C/AL code in this trigger is executed immediately before the system closes the form.

    [Ok]:= OnQueryCloseForm


    Ok
    Data type: boolean

    This return value tells the system whether or not to close the form. The system checks the return value after each function call.


    If Ok is... The system...
    TRUE Closes the form (default)
    FALSE Does not close the form
    Applies to
    Forms


    Comments
    If neither the form nor any child form returns FALSE in this trigger, the system calls the OnCloseForm trigger, first for all child forms and then for the form itself (the parent form).

    If there is an error in the code in this trigger, the system cancels the close action but does not close the form.

    You can write to the database from within this trigger.
    Answer the question and wait for the answer.
  • wonmowonmo Member Posts: 139
    Just put in the OnQueryCloseForm trigger:

    IF NOT Condition THEN
    ERROR('Make condition true');
  • elToritoelTorito Member Posts: 191
    edited 2004-07-21
    Hmm.

    what must i do if i will that the Form doesn't closed.
    in the Online Help are write that OnQueryCloseForm is executed before OnCloseForm. And that the Form doesn't Close if OnQueryCloseForm are FALSE.

    I Have one Value what must be checked before Closed, if the check are ok then it is TRUE if is not ok thenn it is FALSE.

    In the OnQueryCloseForm i try ti open an CONFRIM Dialog,
    but what ever i click, the Form will close.

    I Try with your ERROR() Dialog, but so i don't have any chance to close the Form ... :roll:

    Thanks.
    Form - OnQueryCloseForm() : Boolean
    IF Dialog.CONFIRM('Are you sure?',TRUE) THEN
      Condition := TRUE
    ELSE
      Condition := FALSE;
    IF NOT Condition THEN 
    ...
    

    EDIT:
    Sorry,...

    I have it now...
    in my FUnction what must check the value i was give a MESSAGE Out, now i have changed in ERROR Dialog, so no when i will close the form it says me that if a wrong value and after this it asked me if i would now close or not the form.
    (Oo)=*=(oO)
  • jmjm Member Posts: 156
    Hi,

    please try

    Form - OnQueryCloseForm() : Boolean
    exit(Dialog.CONFIRM('Are you sure?',TRUE));

    br
    Josef Metz
    br
    Josef Metz
  • elToritoelTorito Member Posts: 191
    jm wrote:
    Hi,
    please try
    Form - OnQueryCloseForm() : Boolean
    exit(Dialog.CONFIRM('Are you sure?',TRUE));
    br
    Josef Metz

    Hmm. :?

    I Have a textbox. In the Textbox Trigger OnValidate a execute a function that must check values, if i put in a value in the textbox, and then i go to close form or i press ESC, then the Forms Close, and after the Form was closed i get my Message that Something was do it. But why the Form is now Closed, it don't have affect.
    (Oo)=*=(oO)
  • jmjm Member Posts: 156
    Hi,

    please tell us a little bit more detailed what you want to do.
    if i understood you right, then your code may look as follows:


    OnOpenForm()
    ValuesOk := FALSE;

    OnCloseForm()

    OnQueryCloseForm() : Boolean
    exit(ValuesOk);

    ...


    CheckValues(Input : Code[10]) : Boolean
    if Input = 'X' then
    exit(True)
    else
    exit(False);

    and the Triggers of your Textbox:


    OnAfterValidate()
    ValuesOk := CheckValues(Input);
    if not ValuesOk then
    message('Value %1 is not ok',Input);

    br
    Josef Metz
    br
    Josef Metz
  • elToritoelTorito Member Posts: 191
    jm wrote:
    Hi,

    please tell us a little bit more detailed what you want to do.
    if i understood you right, then your code may look as follows:

    thats right, ...

    in the TextBox Trigger OnValidate I execute my Validate function,...
    thats okay if after change the value i activate another textbox or control,
    but if i change the value without activate another control and i click directly on the closeForm (X) , then the Form will closed, and after it was closed i became the Message that something was do in the validate function.

    I Think that i try execute my Function in another trigger and break with ERROR dialog if occurs something.

    Other Method that i find nice but now i don't know how make it, is when i close the form that will not take changes to my record. I mean, that if i change the value in my textbox and then close the form that the function what i'm execute in the onvalidate trigger don't execute, the form close and nothing will be saved.

    I try now change a little bit the function and try out it in other triggers.


    Perhaps follow way is good...
    When a record will load in the Form then :

    myCheckedVars = TRUE

    When then the validate function execute set
    myCheckVars = FALSE if validate was false
    and
    myCheckVars = TRUE if validate was okay

    and then when i will close the Form
    ask for
    myCheckVars

    if is TRUE Close and if was wrong too close

    hmm.
    (Oo)=*=(oO)
  • ikik Member Posts: 22
    How about in OnQueryCloseForm of the MainMenu
    output text with information of server name and db one
    (using Confirm(varTxt)).

    So in order to find out of db just press 2 keys F12 -> ESC
    from any form. (c) :lol:
Sign In or Register to comment.