Running code at app closing

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I detect when user is closing the app by closing Access (2000) so I
can run some end of day routines?

Thanks

Regards
 
Hi John,

One way is to have a form that you open in hidden mode, via an Autoexec
macro. Add code to the close event of this form. The hidden form can serve
double duty--it can be used to maintain a persistent connection to the BE
(back-end) database in a split multiuser Access application. More details
here:

Implementing a Successful Multiuser Access/JET Application
http://www.accessmvp.com/TWickerath/articles/multiuser.htm


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
I have tried opening my required form in the Close event of the hidden form
but the result is that the required form appears only for a second and then
disappears.

Regards
 
OK, I am now opening my required form as Dialog and it does stay but I don't
have access to it, in that clicking on this form has no effect. Eventually I
have to crash access to get out.
 
If I run the below code in Unload event of hidden form then the required
form MyForm does get control and closing this form allows Access to close
but in a few moments Access crashes with prompt to send error report.

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Do you want to do this before exiting app?", vbQuestion +
vbOKCancel, "App Quiting Process") = vbOK Then
DoCmd.OpenForm "MyForm", acNormal, , , , acDialog
End If
End Sub
 
Hi John,

I haven't tested this; it may or may not work...
Try canceling the unload event of the form if the user clicks on OK:

Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Do you want to do this before exiting app?", _
vbQuestion + vbOKCancel, "App Quiting Process") = vbOK Then
Cancel = True
DoCmd.OpenForm "MyForm", acNormal, , , , acDialog
End If
End Sub


Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 

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

Back
Top