Order of Events using the built in form Close Button

A

accesswanabe

I have a form that is bound to a table that has required fields. When the
form is closed using the Close Button, which is made available to the form by
setting the form's Control Box and Close Button properties to "Yes", Access
displays standard messages about required field data. I would like to
intercept these messages via the order of events that occur when using the
Close Button. Does anyone know what that order of events is?

Thanks much!
 
J

Jeanette Cunningham

The main ones to use are-->
Before Update and Unload.
Both these events allow you to cancel closing the form if required data is
missing.
By the time you get to the Close event, it is too late to stop those error
messages.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
A

accesswanabe

Thanks Jeanette! I stumbled onto an additional way to accomplish this which
accounts for the Access DAO engine generated messages. I'm using the form's
On Error event which, after some testing, appears to be first in the order of
events that occur when using the Close Button (obviously only when Access DAO
engine messages are generated). Using this technique, I can "switch off" the
Access messages (even specific error messages) and customize my response to
the user or omit a response altogether.

I apologize for the duplicate question posting. I was searching for my
question to see if there was any response yet and could not find my original
post, so I re-wrote it.
 
J

Jeanette Cunningham

The form's error event only fires if there is an error - and it is
specifically for some errors and not others.
Many things you do to data on a form will cause the form error event to
fire.
Other things you do on a form can trigger another error handler to run,
those messages can (mostly) be trapped using error handling on your code
routines - example - On Error GoTo Err_Handler
You use something like this

Private Sub SaveIt
On Error GoTo Err_Handler

'code to do whatever you want here

SubExit:
Exit Sub

SubError:
Msgbox Err.Number & " " & Err.Description
Resume SubExit
End Sub



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
J

Jeanette Cunningham

Typo in previous post!
Replace it with this code-->

The form's error event only fires if there is an error - and it is
specifically for some errors and not others.
Many things you do to data on a form will cause the form error event to
fire.
Other things you do on a form can trigger another error handler to run,
those messages can (mostly) be trapped using error handling on your code
routines - example - On Error GoTo Err_Handler
You use something like this

Private Sub SaveIt
On Error GoTo Err_Handler

'code to do whatever you want here

SubExit:
Exit Sub

Err_Handler:
Msgbox Err.Number & " " & Err.Description
Resume SubExit
End Sub
--------------------------------

Or this code-->

Private Sub SaveIt
On Error GoTo SubError

'code to do whatever you want here

SubExit:
Exit Sub

SubError:
Msgbox Err.Number & " " & Err.Description
Resume SubExit
End Sub



Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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