Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shut down pc automatically when Access is exited-How? 1

Status
Not open for further replies.

shineybrick

Programmer
Sep 16, 2001
7
0
0
IE
I can get my db to open straight from Startup. How do I get the reverse? How do I get my pc to automatically shut down, when the db is exited.
The reason is that the user won't be computer savvy.
 
Getting the application to start when you start the PC is easy - simply add it to the "StartUp" folder.

Getting it to automatically shut down the PC when you exit the application - WHY??? These two working in conjunction would mean that you have a PC dedicated to running ONE application. Not a particularly economic or efficient solution. And if your user is so PC-illiterate that they cannot shut down the PC, are they going to be able to use the application correctly in the first place??

A crash course in Basic PC Use might be a better solution.

Lightning X-)
 
Explaination: Correct, the pc is for one application. Some statistical data is entered at intervals, by a select group of general operatives, with basic comp skills.
I have the max/min icons disabled in Access.(Leaving just the exit button). My intention is to give the pc a little protection, from people messing/exploring! Only the select group have passwords.

Ideally, I want the pc to work like an ATM machine, a dumb-terminal.
 
Make a batch file.

Instead of running Access when it starts, have it run the batch file. Have the batch file run Access, and then wait for you to exit Acess. After you exit, have the batch file shut down the machine.
 
Thanks ErikZ,
a 'batch file' may be a direction I want to go in. However, I'm afraid I don't know a thing about batch files.
Also my db has an associated secured.mdw file, and I enter the db through a shortcut with /WRKGRP in its path.
Does this have a bearing on making such a 'batch file'?
 
You can run your application and then shut down your PC with the following instructions in a Batch file:
Code:
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" /wrkgrp yourwrk.mdw "C:\yourapp\yourdb.mdb"
C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows
Then change your desktop shortcut to run the Batch file instead of the Access application.
 
using a batch file wont work.

the batch fill will contuine to run after each command is executed, so in the examole above Access will start to open, then the PC will shout down.

The alternative is

In the main form of the applcation, ad an onexit option to run the batch file containing the line

C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows

Much gooder (and cleaner)
 
I apologize. A Batch file won't work for this situation because it continues to run after launching the Access application.

Try coding the shutdown into the OnClose procedure for your main form:
Code:
Private Sub Form_Close()
  Shell "C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows"
  DoCmd.Quit
End Sub
I think that will work for you as long as no other applications are open.
 
Here's an API call that you can use from within your application. You'll note that you can do other things as well.



'Api function and the constants required for ExitWindowsEx
Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long)

Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1

Private Sub cmdShutdown_Click()

Dim MsgRes As Long

'Make sure that the user really want to shutdown
MsgRes = MsgBox("Are you sure you want to Shut Down Windows?", vbYesNo Or vbQuestion)

'If the user selects no, exit this sub
If MsgRes = vbNo Then Exit Sub

'else, shutdown windows and exit
Call ExitWindowsEx(EWX_SHUTDOWN, 0)
Docmd.Exit

End Sub


"The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
Thanks Dargathi,
I used your advice, but only had partial success though.

I used the OnClose option on my form (because it runs the macro if either the form is closed or Access is exited while the form is open.) to run a macro. The macro uses 'RunApp' to call the Batch file from desktop. A DOS window appears,and then a warning type dialog box appears, which I click 'OK' to "...quit the program and Windows...". But, I wait for minutes and pc doesn't shut down!
I hit CTRL+ALT+DEL and use 'EndTask' on the batch file, and it is only then that the pc shuts down!!

I tested the batch file when no other applications are running, and it worked as expected. ie I double-clicked its icon on desktop, a DOS window appeared, and then I was confronted with a warning dialog box which needed me to click 'OK' to "...quit the program and Windows...". The pc shut down.-Perfect.

I just use the following code in the batch file:
C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows

Do I need to add a line of code to first close Access, and if so, could you please tell me what that code is?

FYI. I don't use VB at all, and am only self taught in Access. Thanks for the VB and API inputs...I must give them some time, sometime. Excuse the pun.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top