on close event

R

Richard

Hi

I am trying to capture changes when the user closes with the form's close
button. What I did was at the onclose event, if changes were made, call up a
message box asking if they want to save.

The problem is that the save procedure has a validation code that checks for
a null value in a certain text box; if so it will stop the procedure and
focus on the textbox. In the onclose event it just closes the form. How
would I overcome this? What event fires when the user closes using the close
button at the top right hand corner of the form?

Thanks in advance
Richard
 
B

Bill Edwards

The unload event will run when a user attempts to close a form:
To see how this works you could put code in the unload event similar to:
IF msgbox("Close form", vbYesNo) = vbNo then
Cancel = true
end if

But a better place to do data validation is the Before Update event of the
form.
 
R

Richard

Hi Bill

Thank for the tip. But if the user chooses to close from the close button,
is there a way to "unclose" the form?

Thanks again
Richard
 
Top