Full Version: Close button X
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
JAVIRAFY
How can I disable the minimize, maximize and close button of Access application?
donpayseur
Go to the Properties of the form and simply choose what features you would like the form to have. i.e.
min,max buttons, close etc.
asmall
Open your form in design view, then set the "Min Max Buttons" to NONE and then set the "Close Button" to NO.

Alton
JAVIRAFY
I meant the Access program min, max and close buttons, not my form
JAVIRAFY
Can anyone help?
Jack Cowley
The attached demo will not affect the minimize and restore buttons but will keep the X button from closing Access. Open the demo (Access2000) and after the splash screen try to click the Access X button. Click on the Enable X button on the form and then the X button will work...

hth,
Jack
R. Hicks
Place the following code in a new module:
CODE
Private Declare Function apiEnableMenuItem Lib "user32" Alias _

"EnableMenuItem" (ByVal hMenu As Long, ByVal wIDEnableMenuItem As Long, _

ByVal wEnable As Long) As Long



Private Declare Function apiGetSystemMenu Lib "user32" Alias _

"GetSystemMenu" (ByVal hwnd As Long, ByVal Flag As Long) As Long



Function EnableDisableCloseButton(bEnable As Boolean, _

Optional ByVal lhWndTarget As Long = 0) As Long

Dim lhWndMenu As Long

Dim lReturnVal As Long

Dim lAction As Long



Const MF_BYCOMMAND = &H0&

Const MF_DISABLED = &H2&

Const MF_ENABLED = &H0&

Const MF_GRAYED = &H1&

Const SC_CLOSE = &HF060&



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



EnableDisableCloseButton = lReturnVal



ErrorHandling_Err:

  If Err Then

    MsgBox Err.Number & ":" & Err.Description

  End If

  

End Function

Now ... in the first form of your application that opens .. place the following in the "On Load" event of the form:
CODE
Private Sub Form_Load()

EnableDisableCloseButton False

End Sub

The above code will disable the Close Button in Access.

Now add the following code to your Exit or Close button in your application:
CODE
Private Sub cmdExit_Click()

EnableDisableCloseButton True

DoCmd.Quit

End Sub

RDH
donpayseur
Wow, good stuff Jack, you are awesome!
Jack Cowley
The thanks go to Richard Rensel for creating the demo and posting it here at Utter Access.... Continued success with your project...

Jack
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.