How to cancel an event?

L

Laurel

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
 
G

Guest

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.
 
L

Laurel

Thank you!

Ken Sheridan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top