On Close vs. On Unload

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the difference between the Close event and the Unload event?

Thanks in advance.

DEI
 
DEI wrote in message
What is the difference between the Close event and the Unload event?

Thanks in advance.

DEI

The most interesting difference from my point of view, is that you can
cancel the closing of the form through the unload event through

cancel = true
 
For sure, but it seems that I can use the 'On Unload' event insteadof the 'On
Close' event.

So, does one supercede the other?
 
DEI wrote in message
For sure, but it seems that I can use the 'On Unload' event insteadof
the 'On Close' event.

So, does one supercede the other?

I'm probably not familiar with the term "supercede", but when you
somehow invoke the process of closing a form, here are some of the
relevant form events, and the order in which they occur

on unload
on deactivate
on close

In the on unload event, as said, you can cancel the closing, which is
what I think is interesting. The other events, as far as I've
understood
does not allow for that, which means - if your intention is to
intervene
with the closing of the form, you must use the on unload event. After
that, the form will close.
 
As Roy-Vidar says, the Unload event can be cancelled, the Close event can't.
So if you want to prevent the form from closing under certain circumstances,
the Unload event is the place to do that. If, on the other hand, you have
some code you want to only run if the form has definitely been closed, and
you do not want that code to run if the closing of the form is cancelled,
then the Close event might be a better choice. You could do it by using an
If ... Then ... Else ... End If in the Unload event, and placing the code
that should run only if the form is definitely going to be closed after the
'Else', but dividing the code between the two events is, in my opinion,
cleaner and more elegant.
 
Back
Top