OnCloseForm - OK button


Is it possible to do a message box that upon closing the form when you press the OK button, it will not exit?

What you are exactly trying to do ?

Yes, it’s possible. You have a couple of choices. You can add code to the OnPush trigger of the OK command button, or you can add code to the OnQueryCloseForm trigger. Problem with the latter option is that a) it is ignorant of and indifferent to the method for arriving at that trigger (could be OK, or Cancel, or ESC?) and b) it always runs whenever you try to close a form.

If you’re trying to ensure that the user has completed a task before closing a form, you may want to consider alternatives. If you use the OnQueryCloseForm trigger, that form will absolutely not close until the condition is met, even if you change your mind and want to abandon the activity. The first approach (OK.OnPush) avoids some of that hassle,but introduces problems of its own. You can put code in the OK.OnPush trigger, but NAV processes the OK Push Event before processing the code in the OnPush trigger; which basically means that NAV will try and fail to close the form, will then raise an error to that effect, and will then run your code in OnPush.

Another approach would be to define the form as a variable and run it that way. Once the user closes the form, you can interrogate the form to determine whether the task is complete before deciding what to do with the data. It’s a bit more coding, but avoids the problems with the other two options of trapping while the form is still open.

Hope that helps …

This scenario is OnCloseForm

for example:

message(‘Customer Name empty’);

in message box… there is only OK button…

When I click the OK button it terminates the program… instead it should retain into the same form and fill up the empty field(s).

under OnQueryCloseForm

IF “Address 2” = ‘’ THEN BEGIN
MESSAGE(‘Please fill up address 2’);

is this valid?

I just want to ask if there is a possibility that if the OK button of the message box is clicked the form will not close thus it will remain open.

What about using ERROR instead of Message?

… but just to be technically correct, you can’t do any of that with the Message command. The message command doesn’t stop processing or raise an error condition, it simply displays a message to the user after the process that calls it finishes.



I was also looking in to a similar problem. OnClosePage trigger i want to perform some checks on the fields of page.

i have written the following code OnClosePage trigger

IF “Cash Account No.” = ‘’ THEN

IF NOT CONFIRM(‘Cash Account No. is empty. Do you want to close the page?’) THEN


This was not working If user select the option yes The Page closes. If the user select No the page still closes.

The solution to this problem is that we have to insert this code on “OnQueryClosePage” Trigger. Beacuse

If the page that is closing and all its child pages return true in the OnQueryClosePage trigger, then the OnClosePage Trigger is called for all child pages and then for the parent page.

If an error occurs in the OnQueryClosePage trigger or it returns false, then the page is not closed.