
This method was derived from two places. The portion disabling the close button in the databases' caption bar is derived from a Google newsgroup search dated May 14th 1999 (comp.databases.ms-access, entitled Disable "CloseApp" button). The portion disabling it form-by form was derived from Chapter 8, p483 of the Access 2000 Developer's Handbook. I found I had to make some minor tweaks to the Developer's Handbook instructions, but otherwise they worked perfectly.
Go to Disable Form Closing
You need to create a module, name it something like mdlDisenableCloseButton. The code follows:
Option Compare Database
Option Explicit
'ACCESS WINDOW MENUS
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As Long, _
ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Private Const MF_BYCOMMAND = &H0&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&
Private Const SC_CLOSE = &HF060&
Public Const WS_SYSMENU = &H80000
Public Const GWL_STYLE = (-16)
Public Const WS_CAPTION = &HC00000
Function EnableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or MF_ENABLED)
End Function
Function DisableCloseButton()
Dim lngSystemMenuHandle As Long
lngSystemMenuHandle = GetSystemMenu(Access.hWndAccessApp, False)
Call EnableMenuItem(lngSystemMenuHandle, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED)
End Function
Function DisAbleTitleBarControls()
Dim lngAccessWindowHandle As Long, lngWindowStatus As Long
lngAccessWindowHandle = Access.hWndAccessApp
lngWindowStatus = GetWindowLong(lngAccessWindowHandle, GWL_STYLE)
lngWindowStatus = lngWindowStatus And (Not WS_CAPTION)
Call SetWindowLong(lngAccessWindowHandle, GWL_STYLE, lngWindowStatus)
End Function
Function EnableTitleBarControls()
Dim lngAccessWindowHandle As Long, lngWindowStatus As Long
lngAccessWindowHandle = Access.hWndAccessApp
lngWindowStatus = GetWindowLong(lngAccessWindowHandle, GWL_STYLE)
lngWindowStatus = lngWindowStatus Or WS_CAPTION
Call SetWindowLong(lngAccessWindowHandle, GWL_STYLE, lngWindowStatus)
End Function
Note: line-wrapping should be okay as it is if you copy & paste, but make sure
Save the module with a meaningful name like mdlDisenableCloseButton.
With the module still open, select "Debug...Compile"
With the module still open, open the "immediate window" by typing CTRL-G. In the ensuing window--which should appear somewhere near the bottom of the module--type:
Call DisableCloseButton()The feature automatically shuts itself off everytime you shut down the database. To make it execute upon startup, simply set it up so that the Call DisableCloseButton() command executes in a form setup to load upon the database initially loading. (Don't know how to do that? Email me.)
| Tab | Property | Setting |
| Format | Control Box | No |
| Close Button | No | |
| Min/Max Buttons | None |
Note: you have to do this for EVERY form you want to have this effect on. If you want to save this step, you can instead type this in the declarations area of any of the modules in the database (certainly a good place would be in the mdlDisenableCloseButton created earlier in this example). (Yes, this is where I had to deviate from the book--or at least clarify what they meant in the book.)