Share via

Disable App Close Button

Anonymous
2011-05-19T19:25:21+00:00

Is there (an easy - wishful thinkful) way to disable the main access close button (x). I have a split db running on clients with the runtime edition of access but some of them are cowboys in that they close the app without obviously going through the right channels.

I have googled this subject but some of the code is simply not understandable or it's just too late at night for me ;)

Any help will be greatly appreciated...

Thank you!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-05-19T23:03:06+00:00

See below:

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

' Source    : http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/5a02a27029c1fe95/4a1445b0712088ab

' Purpose   : Enable/Disable MS Access application Title bar controls (Min, Max, Close)

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

Option Compare Database

Private Declare Function GetWindowLong Lib "user32" _

                Alias "GetWindowLongA" _

                (ByVal hWnd As Long, _

                ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" _

                Alias "SetWindowLongA" _

                (ByVal hWnd As Long, _

                ByVal nIndex As Long, _

                ByVal dwNewLong As Long) As Long

Private Declare Function GetSystemMenu _

                Lib "user32" _

                (ByVal hWnd As Long, _

                ByVal bRevert As Long) As Long

Private Declare Function DrawMenuBar _

                Lib "user32" _

                (ByVal hWnd As Long) As Long

Private Declare Function DeleteMenu _

                Lib "user32" _

                (ByVal hMenu As Long, _

                ByVal nPosition As Long, _

                ByVal wFlags As Long) As Long

Private Const MF_BYCOMMAND = &H0&

Private Const SC_CLOSE = &HF060

Private Const WS_SYSMENU = &H80000

Private Const WS_MAXIMIZEBOX = &H10000

Private Const WS_MINIMIZEBOX = &H20000

Private Const GWL_STYLE = (-16)

Public Function fActivateControlBox(Enable As Boolean)

Dim CurStyle As Long

Dim hWnd As Long

    hWnd = Access.hWndAccessApp

    CurStyle = GetWindowLong(hWnd, GWL_STYLE)

    If Enable Then

        If Not (CurStyle And WS_SYSMENU) Then

            CurStyle = CurStyle Or WS_SYSMENU

        End If

    Else

        If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then

            CurStyle = CurStyle - WS_SYSMENU

        End If

    End If

    Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)

    Call DrawMenuBar(hWnd)

End Function

Public Function fActivateCloseBox(Enable As Boolean)

Dim hMenu As Long

Dim hWnd As Long

    hWnd = Access.hWndAccessApp

    If Enable Then

        Call GetSystemMenu(hWnd, True)

    Else

        hMenu = GetSystemMenu(hWnd, False)

        If hMenu Then

            Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)

        End If

    End If

    Call DrawMenuBar(hWnd)

End Function

Public Function fActivateMaximizeBox(Enable As Boolean)

Dim CurStyle As Long

Dim hWnd As Long

    hWnd = Access.hWndAccessApp

    CurStyle = GetWindowLong(hWnd, GWL_STYLE)

    If Enable Then

        If Not (CurStyle And WS_MAXIMIZEBOX) Then

            CurStyle = CurStyle Or WS_MAXIMIZEBOX

        End If

    Else

        If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then

            CurStyle = CurStyle - WS_MAXIMIZEBOX

        End If

    End If

    Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)

    Call DrawMenuBar(hWnd)

End Function

Public Function fActivateMinimizeBox(Enable As Boolean)

Dim CurStyle As Long

Dim hWnd As Long

    hWnd = Access.hWndAccessApp

    CurStyle = GetWindowLong(hWnd, GWL_STYLE)

    If Enable Then

        If Not (CurStyle And WS_MINIMIZEBOX) Then

            CurStyle = CurStyle Or WS_MINIMIZEBOX

        End If

    Else

        If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then

            CurStyle = CurStyle - WS_MINIMIZEBOX

        End If

    End If

    Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)

    Call DrawMenuBar(hWnd)

End Function

Daniel Pineault - 2010 MVP

http://www.cardaconsultants.com

http://www.devhut.net

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-05-23T21:16:47+00:00

    Works like a blud-e charm! Thank you! God is content again...

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-05-20T18:15:34+00:00

    ok, i take back what i said earlier, i didn't understand where is was making these changes, so everything works. 

    i do notice that when fActivateMinimizeBox (False) is run the minimize disappears from the group in the top right of the Access program "Min, Max, Close."( i don't know what to call it.)

    how do you get the close to disappear?

    Was this answer helpful?

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Anonymous
    2011-05-19T19:42:08+00:00

    not to thwart your efforts, and even though i have seem losts of discussion on the topic, the possible solutions offered are not very effective.  i would love a good one myself.  also, at the end of the day, alt+ctrl+delete and end process or unplug the computer, there will always be cowboys.

    Was this answer helpful?

    0 comments No comments