Shutdown PC through Access button

joeyd11ph

Registered User.
Local time
Today, 07:03
Joined
Jul 16, 2019
Messages
38
Hi Guys,

I'm setting up a dedicated PC to do Access only from powerup to shutdown.

To be exact, when I press the power button of my PC it will boot and start Access and when done, press exit button on Access and it will close Access and shut down the PC. The end-user will not see any Win window.

I managed to do the startup using shell: startup and change personalize settings on background and account pic.

In shutdown, I can't find any VBA to handle the shutdown routine.
My PC is 64-bit Win10 Access 2019.

Appreciate very much if you guys can give me a tip on how to do the SHUTDOWN in ACCES smoothly.

As always,
Thanks, Cheers and more power...
 
Here is the code I've used for the purpose. Place in a standard module
I expect its similar to that in Arnel's example & Gasman's link

Code:
Option Compare Database
Option Explicit

'NOTE switches used below
/s = shutdown
/r = reboot
/l = logoff
/f = force apps to close without warning
/t xxx = time delay of xxx seconds e.g. /t 2

' ‘*******************SHUT DOWN*********************
Public Function TurnOff()
    
    Shell "shutdown /s /t 2", vbHide
    Application.Quit
End Function
 
' ‘*********************REBOOT***********************
Public Function Reboot()
    Shell "shutdown /r /t 2", vbHide
    Application.Quit
End Function
 
' ‘*********************LOG OFF***********************
Public Function LogOff()
    'omit /t switch or it doesn't work
    Shell "shutdown /l", vbHide
    Application.Quit
End Function
 
 '‘**********************FORCE************************
Public Function ForceReboot()
    Shell "shutdown /r /f /t 3", vbHide
    Application.Quit
End Function

With any code of this type, I suggest adding a warning message so user has to confirm action before it runs. Once implemented, the process cannot be interrupted!
For that reason, I also advise users that all work should be saved first
 
I think shutdown using api will not work on windows 10. also if will not work if you have multiple switches.
 
Hi Arnel
If that's a comment on the code I supplied, I've run all of them successfully in Windows 10
 
Definitely works on 32-bit Windows 10.
Can't remember whether I tested in 64-bit.
Can check it later if the OP wants to use my version.

Surprised that it behaves any differently to your code as that looks very similar.
For info, the code I supplied was based on code originally from https://www.lifewire.com/shutdown-command-2618100
 
I am puzzled by the API reference, as I did not spot any?:confused:
 
There is no API call in the code I supplied which is why I queried it in the first place. That is also why I see no reason for it not to work on 64-bit Windows


Sent from my iPhone using Tapatalk
 
I tried it on x64 but doesn't work specially the shutdown.

I've just tested the code I supplied in post #4 using 64-bit Windows 10.
As I expected, all 4 code snippets worked perfectly (as they also do in 32-bit)

@Arnelgp
With no API calls to modify for 64-bit, I see no reason why it shouldn't have worked for you as well. What did happen? What does 'especially the shutdown' mean?
If you tried it in a database that also included your code, perhaps the near duplication caused an issue.
 
Hi Isladogs and others,

Can I use your code using shutdown only? i.e.
' ‘*******************SHUT DOWN*********************
Public Function TurnOff()

Shell "shutdown /s /t 2", vbHide
Application.Quit
End Function

If yes, pls enlighten me more about:
module insertion
or can I just insert it in my VBa event that handle the EXIT sub routine?

Thanks in advance.
Joey


P.S.
Simply inserting in my VBa event that handle the EXIT sub routine did not work.
 
Last edited:
Make a new module from the Create menu or open the Visual BasicEditor and click Insert Module.
You can just include that one function but make sure you get include the twoOption lines at the top
However I suggest you copy all the code I gave in case anything else is useful at a later date.
Save the module as modShutdown or similar

To use the code on your button click event just add the line TurnOff
 
Hi Isladogs

Did as per your instruction but no dice. Maybe I missed something.

Attached is my screenshot.

Thanks

Joey
 

Attachments

  • Capture.PNG
    Capture.PNG
    48 KB · Views: 315
a. I would have thought you would call it before you quit Access.?
b. The function quits Access itself?

Put a MSGBOX after your Docmd.Quit and see what you get.
 
Two things
1. The two lines shown in red in the module code either need to be commented out with an apostrophe at the start of the line or removed completely

2. In your form code, the line before TurnOff needs to be removed. Any code after your application quits doesn’t run! The TurnOff code includes Application.Quit


Sent from my iPhone using Tapatalk

EDIT: Sorry Gasman. I hadn't seen your answer when I posted the above
 
Last edited:
Hi Gasman

Nothing happens as per your instruction.
MsgBox did not appear too.

Thanks

Joey
 
I didn't expect it to.
I suggested the MSGBOX so you could see that anything after the quit would not run.

Colin has confirmed what you need to do.

Please show your current code if you still cannot get it to work.

Hi Gasman

Nothing happens as per your instruction.
MsgBox did not appear too.

Thanks

Joey
 
Hi Isladogs and others,

Successful it works after I commented out the red characters.

Big THANKS, guys.....

Cheers...

P.S.
one more task, I need to disable the X button on the right top corner of ACCESS main window app to fully realize the benefit of this auto shutdown. Any help again will be highly appreciated.
 
SOLVED

Thanks to ISLADOGS and others who in any means tried to help out novice like me. More power to you guys........



Cheers

Joey:):):)
 

Users who are viewing this thread

Back
Top Bottom