Option Compare Database
Option Explicit
'https://social.msdn.microsoft.com/Forums/office/en-US/5e29e4e7-2fcf-4c06-8a0c-be563f3332e3/how-do-disable-close-x-button-in-access-2010-accde-applications
'
' usage:
'
' to enable the X (close button) of Access:
'
' SetAccessCloseButton True
'
' to disable:
'
' SetAccessCloseButton False
'
' VERY GOOD!!
'
#If VBA7 Then
Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As LongPtr, _
ByVal bRevert As Long) As LongPtr
Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As _
LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
#Else
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
#End If
Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&
'Disable the Close Button Option
Public Function SetAccessCloseButton(boolClose As Boolean) As Integer
#If VBA7 Then
Dim hwnd As LongPtr
Dim hMenu As LongPtr
#Else
Dim hwnd As Long
Dim hMenu As Long
#End If
Dim wFlags 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