How to cancel an event?

How to cancel an event?

Post by Laure » Sat, 27 Aug 2005 01:47:46


I want to do some edit checks when the user clicks on the X to close the
form. If they fail, how do I prevent the close from continuing. I see that
I probably need to use the "unload" event instead of the "close" event,
because the help says you can cancel unload. But I don't know how to do the
cancel. I see that it has a parameter "cancel," but I don't see how a
paramter can be used. In peudocode I want to do this when the X is clicked.

If fncCheck <> Success then
<prevent the window from being closed>
end if

There are no "examples" in the help for any events... I also looked around
in Northwind but didn't find anything.

TIA
LAS
 
 
 

How to cancel an event?

Post by S2VuIFNoZX » Sat, 27 Aug 2005 02:18:08

Your are quite right about using the form's Unload event. As you've seen it
has a Cancel argument so you set its return value to True if the validation
fails:

If fncCheck <> Success Then
Cancel = True
End If

or you could use just one line of code:

Cancel = (fncCheck <> Success)

The same applies in other events, particularly the BeforeUpdate event of a
control or form which can be used in exactly the same way at control or form
level. In the latter case this prevents unvalidated data being saved to the
form's underlying table until the user has corrected or undone the changes.

 
 
 

How to cancel an event?

Post by Laure » Sat, 27 Aug 2005 03:31:48

Thank you!