Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Clicking Close Button show message 1

Status
Not open for further replies.

dwlerwill

Technical User
May 25, 2001
329
0
0
Quick Question

I have a database that people do not exit in the correct way (They click the close Access button at the top right (X)) or Task Manager out. This is causing a few problems can I set a message box or something similer in access to pop up if you try to exit in this way?
 
Hi have some code that disables the close button in the top right handside of Access. Quite handy to have. I don't think there is anything that can be done about them using task manager. Let me know your email address if you want we to send some code. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
Hi Nick

my email is

dwlerwill@breathe.com

Cheers

Dave
 
Create a class module and insert this

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&

Public Property Get Enabled() As Boolean
Dim hWnd As Long
Dim hMenu As Long
Dim result As Long
Dim MI As MENUITEMINFO

MI.cbSize = Len(MI)
MI.dwTypeData = String(80, 0)
MI.cch = Len(MI.dwTypeData)
MI.fMask = MF_GRAYED
MI.wID = SC_CLOSE
hWnd = Application.hWndAccessApp
hMenu = GetSystemMenu(hWnd, 0)
result = GetMenuItemInfo(hMenu, MI.wID, 0, MI)
Enabled = (MI.fState And MF_GRAYED) = 0
End Property

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

Call this class closeCommand


NEXT, create a normal module and insert this:

Function InitApplication()
Dim c As closeCommand
Set c = New closeCommand

'Disable Close menu.
c.Enabled = False

'Enable Close menu.
'c.Enabled = True

End Function

click anywhere in this function and hit F5. Can't remember if this falls over on the first time u try it. If it does, don't worry, open up your app and do it again. Hope this is ok. If not, just let me know.

Nick (Everton Rool OK!)
 
That works but what do I need to do to get it to run automatically on startup?
 
Aaaaaaa

Just worked it out, Thanks for all your help
 
Pardon my ignorant.

I always thought that when the X of the access is clicked, the sub windows are closed and thus you should have a chance to execute some codes on form close to properly exit your program or show a dialog box to request the user to exit correctly.

If you disabled the X of the access, I would expect users who want to click the X will turn to using the task manager :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top