Disable right click / close on database

dzirkelb

Registered User.
Local time
Today, 06:27
Joined
Jan 14, 2005
Messages
180
Is there a way to disable the option to right click on the database (on the taskbar) and then select close? I want the only way to close out of the program to be if they click my close button which I have made.
 
Disable

Please search the forum, there are several posts on this subject.
 
Go to Tools>Startup and then Untick all options there. For each of your forms go to the form properties and set Menu=0. With your database open close the toolbar and press ctrl plus S and then close the database.
Chris
 
I searched teh forums and only found disable right clicking for menu shortcuts...I wish to disable the right click on the taskbar of windows (next to start key) and disable that close function...basically, I only want the database able to be closed unless my close databaes button is pushed. I know I can disable it in the registry, but, thats global.
 
I haven't seen that being done by code till date but that doesnt mean its not possible.

Macro to disable X button:
to call: EnableDisableControlBox (False)
Option Compare Database
Option Explicit


'**********************************************************

'We need the following API declarations first
Public Declare Function apiEnableMenuItem Lib "user32" Alias "EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, ByVal wEnable As Long) As Long
Public Declare Function apiGetSystemMenu Lib "user32" Alias "GetSystemMenu" (ByVal hWnd As Long, ByVal flag As Long) As Long

Public Function EnableDisableControlBox(bEnable As Boolean, Optional ByVal lhWndTarget As Long = 0) As Long
On Error GoTo ErrorHandling_Err

' ----------------------------------------------------------------------
' Purpose: Example of how to disable or enable the control box of
' a form, report, or the Access parent window.
'
' Accepts: bEnable, which determines whether to disable or enable
' the control box
'
' Also accepts lhWndTarget (which is optional), if you want
' to use a window handle other than the Access parent window.
'
' Returns: N/A
'
' Example usage: lRetVal = EnableDisableControlBox(True) to enable -OR-
' lRetVal = EnableDisableControlBox(False) to disable
'
' NOTE: If no hWnd is passed in for a specific form, then the code
' assumes you want to enable/disable the Access parent window
' ----------------------------------------------------------------------

Const MF_BYCOMMAND = &H0&
Const MF_DISABLED = &H2&
Const MF_ENABLED = &H0&
Const MF_GRAYED = &H1&
Const SC_CLOSE = &HF060&

Dim lhWndMenu As Long
Dim lReturnVal As Long
Dim lAction As Long

lhWndMenu = apiGetSystemMenu(IIf(lhWndTarget = 0, Application.hWndAccessApp, lhWndTarget), False)

If lhWndMenu <> 0 Then
If bEnable Then
lAction = MF_BYCOMMAND Or MF_ENABLED
Else
lAction = MF_BYCOMMAND Or MF_DISABLED Or MF_GRAYED
End If
lReturnVal = apiEnableMenuItem(lhWndMenu, SC_CLOSE, lAction)
End If

EnableDisableControlBox = lReturnVal

ErrorHandling_Err:
If Err Then
'Trap your error(s) here, if any!
End If

End Function
Chris
 
Last edited:
That code is over my head unfortunately...what would I do with it? would I put it on every form I wanted this to happen to at the top? What would I say to tell it to disable the right click / close feature?

If they close the form, then I want whatever data they entered in the form to be cleared out from the table ultimately.
 
If you set your form properties for pop-up and modal to 'Yes' then the user won't be able to use the right click and close...this works well. However, it opens up too big (or too long) as the bottom of the form is underneath the taskbar of my machine...any ideas on how to get it to be the size of the screen like IE is when maximized or any other program for that matter?
 
answered my own question...I made the windows border style set to none nad it works just fine..thanks!
 

Users who are viewing this thread

Back
Top Bottom