T
tkosel
I have been using the code below in a bunch of applications for quite some
time. It prevents the user from closing the Access program (Access 2003 and
older) using the application close button. It works great, I make the user
exit using a control on my form. However, it does not work in Access 2007.
Can anyone suggest why? Any way that you can see to make it work like it
used to?
Option Explicit
Option Compare Database
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long,
ByVal wRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Public Sub FMS_AppCloseEnabled(pfEnabled As Boolean)
' Comments: Control the Access close button.
' Disabling it forces the user to exit within the application
' In : pfEnabled TRUE enables the close button, FALSE disabled it
' Owner : Copyright (c) 2008 from FMS, Inc.
' Usage : Permission granted to subscribers of the FMS Newsletter
On Error Resume Next
Const clngMF_ByCommand As Long = &H0&
Const clngMF_Grayed As Long = &H1&
Const clngSC_Close As Long = &HF060&
Dim lngWindow As Long
Dim lngMenu As Long
Dim lngFlags As Long
lngWindow = Application.hWndAccessApp
lngMenu = GetSystemMenu(lngWindow, 0)
If pfEnabled Then
lngFlags = clngMF_ByCommand And Not clngMF_Grayed
Else
lngFlags = clngMF_ByCommand Or clngMF_Grayed
End If
Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
End Sub
time. It prevents the user from closing the Access program (Access 2003 and
older) using the application close button. It works great, I make the user
exit using a control on my form. However, it does not work in Access 2007.
Can anyone suggest why? Any way that you can see to make it work like it
used to?
Option Explicit
Option Compare Database
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long,
ByVal wRevert As Long) As Long
Private Declare Function EnableMenuItem Lib "user32" (ByVal hMenu As _
Long, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
Public Sub FMS_AppCloseEnabled(pfEnabled As Boolean)
' Comments: Control the Access close button.
' Disabling it forces the user to exit within the application
' In : pfEnabled TRUE enables the close button, FALSE disabled it
' Owner : Copyright (c) 2008 from FMS, Inc.
' Usage : Permission granted to subscribers of the FMS Newsletter
On Error Resume Next
Const clngMF_ByCommand As Long = &H0&
Const clngMF_Grayed As Long = &H1&
Const clngSC_Close As Long = &HF060&
Dim lngWindow As Long
Dim lngMenu As Long
Dim lngFlags As Long
lngWindow = Application.hWndAccessApp
lngMenu = GetSystemMenu(lngWindow, 0)
If pfEnabled Then
lngFlags = clngMF_ByCommand And Not clngMF_Grayed
Else
lngFlags = clngMF_ByCommand Or clngMF_Grayed
End If
Call EnableMenuItem(lngMenu, clngSC_Close, lngFlags)
End Sub