Exit Windows Under Program Control
Problem
You’d like to be able to control what happens once you quit your applications: you may want to shut down Windows at the same time, or perhaps even reboot the machine. How can you do that from within Access?
Solution
The Windows API provides an ExitWindowsEx function that grants you control over exiting Windows, and you have a choice of three different things you can do: log off and await a new login; shut down to the point at which it’s safe to turn off the computer’s power; or reboot the computer. This solution demonstrates these simple functions.
To try closing Windows under program control, load and run
frmExitWindows from 11-06.MDB. This sample form,
shown in Figure 11-7, allows you to choose from the
three options. Make your choice and click on the Go button, which
will execute the code necessary to quit in the manner you’ve
specified.

Figure 11-7. frmExitWindows presents three options
To use this functionality within your own applications, follow these steps:
Import the module basExitWindows from
11-06.MDB.Call the function from Table 11-4 that best suits your needs. In each case, if the function returns at all, it indicates that some Windows process wasn’t able to shut down and that your function call failed. This won’t happen often.
Table 11-4. Available functions for exiting Windows
Function
Description
acbLogOff
Shuts down ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access