Most of the code for this FAQ came from the Access 2000 Developer's Handbook Volume 1: Desktop Edition by Fetz, Litwin, and Gilbert, Published by Sybex. I cannot take credit for the code. Although this is publsihed in an Access 2000 manual, I have successfully used this in Access 97 as well and believe it will work in Access 20002.
Access allows you to remove the little 'x' in the right hand corner of your form, and there is even a way to remove the 'x' for the application itself (but this is much more detailed, involving API calls and the like and is not discussed in this FAQ). But your users can still close the apllication by using Ctrl+F4 or Alt+F4 to close you forms. You could use the AutoKeys option and remap these keys to nothing or a message saying it is disabled, but this method simply cancels the closing of the form. If you are using some main screen for your application, by placing this procedure on that form, you will effectively prevent your users from closing your database except by the method you provide.
1. Set the CloseButton propert of the form to No. You can alternately set the ControlBox property to No, which removes both the 'x' and the min max buttons.
2. In the declaration's area of the form's VBA code, define the followinf variable:
Public OK2Close As Boolean
3. In the form's OnLoad event, place the following code:
OK2Close = False
4. On your form should be a button to close the form (or Quit the application if on the Main screen). In the OnClick event for this button, place:
OK2Close = True DoCmd.Close '(or DoCmd.Quit for Main screen)
5. In the form's Unload event, place:
Cancel = Not OK2Close
That's it....the above 5 steps and you now have a form (or application) that cannot be closed except by the method you have provided.