Trapping The Close Button

E

Eric

Is it possible to trap the Close Button (the X at the top
right-hand corner) of the Access application?

Allow me to qualify this by saying that it is different to
the Close button that appears on the forms. The Close
button can be switched on and off via the properties of
the form.

I need to trap for this because it is not intended that
users exit the Access application in this manner, but
rather through a button which logs user history of logouts.
 
A

Allen Browne

There is no built-in event for this.
It is commonly simulated with the Close event of a hidden form.
 
G

Guest

Do the following:
Place this in the declaration of a class module: I use these in a library database

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
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Long, lpMenuItemInfo As MENUITEMINFO) As Long

Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type

Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&

In that module create:
Public Property Let Enabled(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 Property

Create the following function and attach it to the open even of your splash form.
Function InitApplication()
Dim C As 'UsysMod_RFlib_Close_Properties' 'CloseCommand the 'UsysMod...etc is the name of the modeule"
Set C = New UsysMod_RFlib_Close_Properties 'CloseCommand
C.Enabled = False
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top