Article ID: 300688 - View products that this article applies to.
This article was previously published under Q300688
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
For a Microsoft Access 2000 version of this article, see 245746
For a Microsoft Access 97 version of this article, see 258049
Microsoft Access has no built-in method for disabling the Close button (X) on the application window, the Close command on the System menu of the application window, or the Exit command on the File menu. This article describes how to programmatically disable all of these.
CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
In order to disable the application Close button and the Close command on the System menu, you must call the GetSystemMenu and EnableMenuItem functions from the Win32 API.
In order to disable the Exit command on the File menu, you must use the CommandBars collection, which exposes all menu bars, toolbars, and shortcut menus in your application to Visual Basic for Applications so that you can manipulate them programmatically.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
UsageThe code described in this article allows you to easily enable or disable the Close button, the Close command of the application window, and the Exit command on the File menu to prevent users from exiting the application by using these methods.
Please note that this technique affects the Close button on the application window of Microsoft Access, not the Close button on the Database window. After disabling these options, neither is automatically re-enabled when your database closes. If the user closes the database and leaves Microsoft Access open, the user will not be able to quit Microsoft Access by using the Close button or the Exit command on the File menu. In this case, your application should re-enable both options before it terminates. Otherwise, the user will have to quit and restart Microsoft Access in order for the Close button and the Exit command on the File menu to be enabled.