Disable Access close button (1 Viewer)

bjsteyn

Registered User.
Local time
Today, 21:14
Joined
May 15, 2008
Messages
113
How do I disable the main access window's close/exit button in the top right corner?

Thanks bj
 

Guus2005

AWF VIP
Local time
Today, 20:14
Joined
Jun 26, 2007
Messages
2,641
RTBC pt.1

(Reasons 2 b cheerfull pt.1)
 

Attachments

  • db30.zip
    11.1 KB · Views: 1,203

bjsteyn

Registered User.
Local time
Today, 21:14
Joined
May 15, 2008
Messages
113
Hey Guus2005, I am looking for code to disable the access close button of the main access window.

thanks bj
 

jsv2002

Registered User.
Local time
Today, 19:14
Joined
Feb 11, 2009
Messages
240
Copy the following into a new module:
Code:
Option Compare Database
Option Explicit


Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
Private Const HWND_TOP = 0
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Sub HideAccessCloseButton()
    Dim lngStyle As Long
    lngStyle = GetWindowLong(hWndAccessApp, GWL_STYLE)
    lngStyle = lngStyle And Not WS_SYSMENU
    Call SetWindowLong(hWndAccessApp, GWL_STYLE, lngStyle)
    Call SetWindowPos(hWndAccessApp, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_DRAWFRAME)
End Sub
Then from your main forms on load event call it with:
Code:
'Call module to hide access application close button
    HideAccessCloseButton
Good luck John :)

PS. Make sure you have a way to close/quit the database as GUUS2005 has showed in his sample or you will and up using task manager or right click close and not quiting the application correctly!
 
Last edited:

Guus2005

AWF VIP
Local time
Today, 20:14
Joined
Jun 26, 2007
Messages
2,641
@jsv2002: Do you have code to enable it again?
 

jsv2002

Registered User.
Local time
Today, 19:14
Joined
Feb 11, 2009
Messages
240
@jsv2002: Do you have code to enable it again?

Somewhere might take me a while to find it though... usually only works when called so if not needed just ' out and restart the db window should be back :)
 

bjsteyn

Registered User.
Local time
Today, 21:14
Joined
May 15, 2008
Messages
113
Hey there thanks. Put the code into my db and is working perfecty.
 

MLUCKHAM

Registered User.
Local time
Today, 19:14
Joined
Jul 23, 2013
Messages
89
If your database is form driven (and most are) then just put some code on the Form_Unload event. This will prevent anyone closing the main database screen or the form.

Code:
Private Sub Form_Unload(Cancel As Integer)

    If MsgBox("Are you sure you want to quit this application?", vbYesNo + vbQuestion, "Application Quit") = vbNo Then
        Cancel = 1
    End If
    
End Sub

Just be warned that you may need to add some further code to stop the msgbox from showing on the occasions that you want to unload the form without user intervention.
 

mjhd786

New member
Local time
Today, 11:14
Joined
Feb 19, 2015
Messages
3
This code worked for me...is there a way to keep th emin/max buttons though and just disable the close?

Thanks

:confused:
 

mjhd786

New member
Local time
Today, 11:14
Joined
Feb 19, 2015
Messages
3
If your database is form driven (and most are) then just put some code on the Form_Unload event. This will prevent anyone closing the main database screen or the form.

Code:
Private Sub Form_Unload(Cancel As Integer)
 
    If MsgBox("Are you sure you want to quit this application?", vbYesNo + vbQuestion, "Application Quit") = vbNo Then
        Cancel = 1
    End If
 
End Sub

Just be warned that you may need to add some further code to stop the msgbox from showing on the occasions that you want to unload the form without user intervention.

This is useful, but it quits when you click no as well. I tried Cancel = True but doesn't work either.
 

rzw0wr

I will always be a newbie
Local time
Today, 14:14
Joined
Apr 1, 2012
Messages
489
I have been looking for the answer to this question for several months.
I should have known I would find it here.

This program works great.



Thank you,
Dale
 

Users who are viewing this thread

Top Bottom