On Close vs. On Unload

G

Guest

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

Thanks in advance.

DEI
 
R

RoyVidar

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
 
G

Guest

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

So, does one supercede the other?
 
R

RoyVidar

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

Brendan Reynolds

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.
 

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

Similar Threads


Top