Create a 'background' form and open it hidden when your application starts up:
Code:
DoCmd.OpenForm "Background", , , , , acHidden
In the form's Unload event procedure, put the following code:
Code:
Cancel = True
MsgBox "Please use the Exit button to close the application"
This works because Access begins its shutdown by closing all forms. This Unload event gets raised when the Background form is being closed. By setting the Cancel parameter to True, it aborts the form close, which aborts the shutdown.
Let me suggest, however, that you go ahead and let them use the Access X button. All you have to do is call the same code from the background form's Close event that you currently call from your Exit button. If you do this, you should either eliminate the Exit button or you should change its Click procedure to:
The reason is that, if your Exit button calls your VBA code and then shuts down the application, Access will try to close the Background form, which will raise its Close event, and the form will try to call your VBA code again.
Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein