Capturing a form close

R

Randy K.

I have a form that starts in a listbox that has an onexit procedure defined
to ensure an item in the list is selected before continuing. If an item
isn't selected, a msgbox appears and the exit is canceled. But, when the
form is just opened and then closed (via clicking the 'X' or double-clicking
the forms icon), I don't want the procedure to run or want to put an if
statement in the procedure to skip the validation check.

How do I know, via code, that the X has been clicked or icon double clicked
so I can skip all processing and let the form close without msgbox(es) to
users?

TIA,
Randy
 
R

Randy K.

The control's OnExit fires before the form's OnClose. I need something I
can put in the OnExit code to check if trying to close the form, then I can
skip the validation and msgboxes.

Randy
 
B

Barry Gilbert

I'm still not sure I understand, but here goes:
Create a command button that runs your code and then closes the form. Don't
use the form's OnExit or OnClose events. If the user clicks the button, the
code is run. If they click the x, the code doesn't run. You could also put a
Cancel button on the form that closes the form without processing.

Barry
 
R

Randy K.

Correct, I can code my own close button and disable the regular close button
for the form, but then this (and 1 other) form would be different than the
other 30+ forms within the app and that was the situation I was hoping to
avoide. May be the only alternative, but was hoping that a property would
get set or something that I could check with the controls OnExit routine to
stop that routines validation processing. May not be able to do what I am
hoping to do.

Randy
 

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