'database close' event

  • Thread starter Thread starter Jesse Aufiero
  • Start date Start date
J

Jesse Aufiero

How can i execute code when the access database application closes. is
there a way to hook into a 'database_close' event, or the like? thanks!
 
Jesse,

As far as I know, this is not directly possible.

One way to handle this kind of requirement is to enforce that the only
way the application can be closed is via a command button on a form
which is always open when the application is open. The means of doing
this is like this...

In the Declarations section at the top of the code module for the form,
put like this...
Dim AllowClose As Boolean

On the Load event of the form, put...
AllowClose = False

On your 'Exit' button, put...
AllowClose = True
DoCmd.Close acForm, Me.Name
DoCmd.Quit

On the Unload event of the form, put...
If AllowClose Then
' < your code that you want to run when the app closes >
Else
MsgBox "Use Exit button to close", vbExclamation, "Illegal escape"
Cancel = True
End If
 
Jesse

One way you could do this would be to open a form when the application
opens, but open it "hidden".

In THAT form's OnClose event, put what you want to have happen.

When the database closes down, that form closes and your code is triggered.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
If you have a form that stays open as long as your application is open, you
can put the cde in the Close event of that form. The form can be visible or
hidden.
 
.... or, if you prefer to do it the easy way, follow Jeff's and Klatuu's
advice ;-)
 
Back
Top