View Full Version : AutoExec but is there an AutoCloseExec?


ions
09-18-2006, 10:44 PM
I would like to run code when the user presses the X button. I've read that the only way to do this is is to load a hidden form during StartUp (AutoExec) and put the code on the Unload event of that form. (Also it has been mentioned that this can potential not work in certain circumstances.)

Is this true..... this is the only way? I just can't believe it.... so making sure.

I would like to run Ghudson's code on close. Nice work Ghudson

Public Function CompactOnClose()
On Error GoTo Err_CompactOnClose

If FileLen(CurrentDb.Name) > 5000000 And CurrentUser <> "programmer" Then '5 megabytes
Application.SetOption ("Auto Compact"), 1
Application.SetOption "Show Status Bar", True
vStatusBar = SysCmd(acSysCmdSetStatus, "The application must be compacted, please do not interfere with the Compacting process!")
Else
Application.SetOption ("Auto Compact"), 0
End If

Exit_CompactOnClose:
Exit Function

Err_CompactOnClose:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_CompactOnClose

End Function

mhartman
09-19-2006, 05:59 AM
Hello

Yes. put your code on the ONCLOSE event of your form.
Regards
Mark

ghudson
09-19-2006, 01:28 PM
I prefer to disable the applications control box X button so that the user has to use my "Exit" database command button when they want to close the application.

Enable/Disable The Control Box X Button (http://www.access-programmers.co.uk/forums/showthread.php?t=98554)

:cool: