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