Shutdown PC through Access button

Glad to hear its now working for you. I've marked the thread as SOLVED.
Does that mean you've worked out how to remove/disable the red X at the top right?
 
Hello Isladogs,

Still, I'm searching for a logical approach to disable the min, max and close X control on the topmost upper right corner of the ACCESS main app window.

Again I appreciate very much if anybody can share their expertise.

Thanks in advance.

Joey
 
copy and paste in a module.
create an Autoexec macro and RunCode.
the X button will still be visible but is disabled:
Code:
Option Compare Database
Option Explicit

'https://social.msdn.microsoft.com/Forums/office/en-US/5e29e4e7-2fcf-4c06-8a0c-be563f3332e3/how-do-disable-close-x-button-in-access-2010-accde-applications
'
' usage:
'
' to enable the X (close button) of Access:
'
' SetAccessCloseButton True
'
' to disable:
'
' SetAccessCloseButton False
'
' VERY GOOD!!
'
#If VBA7 Then
Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As LongPtr, _
    ByVal bRevert As Long) As LongPtr

Private Declare PtrSafe Function EnableMenuItem Lib "user32" (ByVal hMenu As _
    LongPtr, ByVal wIDEnableItem As Long, ByVal wEnable As Long) As Long
#Else
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
#End If


Const MF_GRAYED = &H1&
Const MF_BYCOMMAND = &H0&
Const SC_CLOSE = &HF060&


'Disable the Close Button Option
Public Function SetAccessCloseButton(boolClose As Boolean) As Integer
#If VBA7 Then
    Dim hwnd As LongPtr
    Dim hMenu As LongPtr
#Else
    Dim hwnd As Long
    Dim hMenu As Long
#End If
    Dim wFlags 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 Function
 
Hi arnelgp,

Following your instruction, I got red characters, see attached...

I stop from there thinking maybe I did something wrong.

Please enlighten me.

Thanks.

Joey
 

Attachments

  • Capture.PNG
    Capture.PNG
    27.2 KB · Views: 190
it's ok, the red line are for compatibility only for older version of access.
 
Hi Arnel,

What Function name I will use?

I tried SetAccessCloseButton but I have error msg, see attached.


Tnx

Joey
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    32.3 KB · Views: 181
put the code in a Standard Module (in VBA->Insert->Module).
save the module which is different from the name of the function (eg. modDisableEnableXButton).
Code:
RunCode SetAccessCloseButton(False)
 
Hi Arnelgp,

Thank you very much, it works as expected.

How can I include the min and max button?

Cheers,

Joey
 
SOLVED

Thanks to arnelgp and others for their kind help.

Cheers,

Joey
 
Works for me on 32bit Win10 ?
 
Hi Gasman,

Just a clarification if you just follow the instruction from the link straight through without any modification?

Mine is an error msg saying it will not work for 64 bit in RED LINE.

If yes maybe I will change my setup to 32bit, any advise will be highly appreciated.

Thanks

Joey
 
I was querying what you did to solve it, as that could help others.?

I just copied the code as is, no modification, and it worked.
Then I could not close Access. :D

Now I have followed the link to show the buttons and placed that in as well.

If you are running 64bit Access then you will need to follow these instructions to get it to work.

Plus arne works in 64bit I believe, so he should be able to help.?

https://docs.microsoft.com/en-us/office/client-developer/shared/compatibility-between-the-32-bit-and-64-bit-versions-of-office
 
Hi Gasman,

The solved part is the X button only, Im still searching for Min/Max butoon.

Please bear with me, can you please give me a step by step how you did it.

Thanks
Joey
 
Hi Joey
If you want to remove or disable all three controls, I would use the alternative suggestion I mentioned in post #24. Removing the title bar and application window gives an all in one solution which you can see in my example app.
 
Hi Gasman,

The solved part is the X button only, Im still searching for Min/Max butoon.

Please bear with me, can you please give me a step by step how you did it.

Thanks
Joey

It removes ALL three buttons for me.? :confused:
 
Hi joey
You can use code such as that supplied by arnel or in this link https://www.fmsinc.com/microsoftaccess/startup/preventclose.asp...OR you can remove the title bar completely together with the application window. See my example app https://www.access-programmers.co.uk/forums/showthread.php?t=293584

Hi Isladogs,

I downloaded your file and played with it to familiarize with the in and out of the program. I find it very good.

I tried to strip down items I don't need and keep the item I need to hide the min, max, and x close button.

All my efforts are in futile, I'm sure I missed something here.
Please bear with me and let me know the steps in applying only code to hide the min, max, and x close button in my Main Menu form.


Please see my attachment.

Thanks

Joey
 

Attachments

  • Capture.jpg
    Capture.jpg
    92.8 KB · Views: 188
  • Capture1.PNG
    Capture1.PNG
    29.8 KB · Views: 178

Users who are viewing this thread

Back
Top Bottom