The common technique is to create a blank form and run your code from the form's unload event which you can cancel if necessary. You then open this form as your startup form and have this form hide itself and open your regular switchboard. When Access is shut down, this hidden form will be the last form closed and it will run your "exit" code as it attempts to unload itself.