Disable Close Button Access 2013

billgyrotech

Banned
Local time
Yesterday, 18:42
Joined
Apr 18, 2013
Messages
258
Does anyone know how to disable the main close button so the user is forced to click the Quit Application button on my main switchboard?

Thanks for any help,
Bill
 
You can try using this code (put into a new standard module):

Code:
Option Compare Database
Option Explicit
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
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
Public Function SetEnabledState(blnState As Boolean)
    Call CloseButtonState(blnState)
    Call ExitMenuState(blnState)
End Function
 
'Disable the Menu Option
Function ExitMenuState(blnExitState As Boolean)
    Application.CommandBars("File").Controls("Exit").Enabled = blnExitState
End Function
 
'Disable the Close Button Option
Function CloseButtonState(boolClose As Boolean)
    Dim Hwnd As Long
    Dim wFlags As Long
    Dim hMenu As Long
    Dim Result As Long
       
    Hwnd = Application.hWndAccessApp
    hMenu = GetSystemMenu(Hwnd, 0)
    If Not boolClose Then
        wFlags = MF_BYCOMMAND Or MF_GRAYED
    Else
        wFlags = MF_BYCOMMAND And Not MF_GRAYED
    End If
    
    Result = EnableMenuItem(hMenu, SC_CLOSE, wFlags)
End Function
 
I tried this code but the button is still enabled.
 
Did you call that function in an AutoExec macro?
 
You need to create a macro and name it AutoExec (exactly like that).

In the Action for the macro use

RunCode

and in the arguments area use:

CloseButtonState False


If you open the database holding the shift key, it will bypass that so it won't be disabled but if you open it normally it will be disabled if the code works with 2013. It works in 2007 but that's as far as I've tested.
 

Users who are viewing this thread

Back
Top Bottom