CloseQuery event
Description
Occurs when a window is closed, before the Close event.
Event ID
|
Event ID |
Objects |
|---|---|
|
pbm_closequery |
Window |
Parameters
None
Return Values
Long. Return code choices (specify in
a RETURN statement):
-
0 Allow the
window to be closed -
1 Prevent the window from closing
Usage
If the CloseQuery event returns a value of 1, the closing
of the window is aborted and the Close event that usually follows
CloseQuery does not occur.
If the user closes the window with the Close box (instead
of using buttons whose scripts can evaluate the state of the data
in the window), the CloseQuery event still occurs, allowing you
to prompt the user about saving changes or to check whether data
the user entered is valid.
Obsolete techniques
You no longer need to set the ReturnValue property of the
Message object. Use a RETURN statement instead.
Examples
This statement in the CloseQuery event for a window
asks if the user really wants to close the window and if the user
answers no, prevents it from closing:
|
1 |
IF MessageBox("Closing window", "Are you sure?", & |
|
1 |
   Question!, YesNo!) = 2 THEN |
|
1 |
   RETURN 1 |
|
1 |
ELSE |
|
1 |
   RETURN 0 |
|
1 |
END IF |
This script for the CloseQuery event tests to see
if the DataWindow dw_1 has any pending
changes. If it has, it asks the user whether to update the data
and close the window, close the window without updating, or leave
the window open without updating:
|
1 |
integer li_rc |
|
1 |
|
1 |
// Accept the last data entered into the datawindow |
|
1 |
dw_1.AcceptText() |
|
1 |
|
1 |
//Check to see if any data has changed |
|
1 |
IF dw_1.DeletedCount()+dw_1.ModifiedCount() > 0 THEN |
|
1 |
   li_rc = MessageBox("Closing", & |
|
1 |
   "Update your changes?", Question!, & |
|
1 |
   YesNoCancel!, 3) |
|
1 |
|
1 |
   //User chose to up data and close window |
|
1 |
   IF li_rc = 1 THEN |
|
1 |
      Window lw_window |
|
1 |
      lw_window = w_genapp_frame.GetActiveSheet() |
|
1 |
      lw_window.TriggerEvent("ue_update") |
|
1 |
      RETURN 0 |
|
1 |
|
1 |
   //User chose to close window without updating |
|
1 |
   ELSEIF li_rc = 2 THEN |
|
1 |
      RETURN 0 |
|
1 |
|
1 |
   //User canceled |
|
1 |
   ELSE |
|
1 |
      RETURN 1 |
|
1 |
   END IF |
|
1 |
|
1 |
ELSE |
|
1 |
   // No changes to the data, window will just close |
|
1 |
   RETURN 0 |
|
1 |
END IF |
|
1 |