Rivercity Technology Services LTD Logo
About Us
Services
Icon showing a support technician
IT Support Services
Cybersecurity Risk Management at one predictable flat rate.
Icon of light bulbs on a laptop screen
IT Consulting
Business optimization through the smart use of technology.
Icon showing a hand holding a phone
Business Phone Services
VoIP Telephone solutions from RCT. 
Icon showing a database and a cloud
Backups & Recovery
Cloud & On Premise - ready to recover!
Icon showing website wireframes
Website Development & Hosting
Web design and full hosting & maintenance packages!
Icon showing an envelope being opened
Modern Email Management
Microsoft 365 email provisioning, security & management.
Icon of a magnifying glass inspecting binary code on a computer screen
Cybersecurity Risk Assessment
Internal auditing to help identify potential cyber threats.
“You’re giving me the ‘it’s not you, it’s me’ routine? I invented ‘it’s not you, it’s me.’ Nobody tells me it’s them not me; if it’s anybody, it’s me.”
- George Costanza
Learning CenterNewsletterContact Us
Book A Consultation
Illustration of a person writing a blog post with a pencil

Sign out of Computer Upon Exiting Access Database

If you ever come across a scenario where you want to sign the user out of the computer upon exiting Access database, then this guide will help you! In our scenario, a client has a remote server where the database launches upon login, and we want them to be logged off upon exit, to result in no access to the server itself.

Here are the steps:

You need to create a hidden form, as there is no default action to detect access closing. On the Access Ribbon, navigate to Create > Form Design. In the properties of the form under Event > On Unload put the following VBA code:

Private Sub Form_Unload(Cancel As Integer)
LogOffPC
End Sub

Save the form. In our example, we named the form "frmLogOff".

Next, we need to create an Auto Exec Macro which will launch our hidden form upon the opening of the database. Go to Create > Macro. In Form Name select "frmLogOff" and make sure to switch Window Mode to "Hidden". Make sure to save the macro as "AutoExec" as its the default macro name that Access checks for upon load.

Now we must create the Module Function for the logoff. Navigate to Create > Module and insert the code below:

Declare Function ExitWindowsEx& Lib "user32" (ByVal uFlags&, ByVal wReserved&)
 
 '//constants needed to exit Windows
Global Const EWX_LOGOFF = 0
Global Const EWX_SHUTDOWN = 1
Global Const EWX_REBOOT = 2
Global Const EWX_FORCE = 4


 '//log-off
Sub LogOffPC()    
    call  ExitWindowsEx(EWX_LOGOFF, 0&)
End Sub

In our example, we saved the module name as "ModLogOff"

That's it! The next time you open your database, the hidden form "frmLogOff" will run with your default form. Whenever you decide to exit out of the database, "frmLogOff" closes and runs the command to log out of Windows.

If you have any questions, feel free to talk to us on the live chat, or give us a call during business hours. Happy coding!

Mitch Redekopp
Article Written by Mitch Redekopp

Get in Touch

Need IT Services or Cybersecurity for your business? Have tech questons? Contact us today, we'd love to help you!
Blog Sidebar Contact Form
Related Articles
Rivercity Technology Services LTD logo
We are your IT department. How would you like to manage your risk?
201-116 Research Dr,
Saskatoon, SK
S7N 3R3

306-933-3355

Copyright © 2024 - All Rights Reserved

crossmenu