How to set a timer on an Microsoft Access database
In this article we explore the procedure to wow to set a timer on an Microsoft Access database so that it closes automatically after a timeout
There might be occasion where you want to have a time on your Microsoft Access Database 365. On my case we have a timer of 5' that pops up a scary window after that amount of inactivity, and it automatically closes the database saving all the work, cool ah?
First of all create a Form called "frmInactiveShutdown", I designed like this:
Still on the design section of the form, click on the big square to open the Properties Sheet, visit the "Event" tab, and on the field On Open, select Event Procedure, then click on the 3 dots next to it...
That will open Microsoft Visual Basic, with the entry for the form, paste on the form all this code below:
Option Compare Database Option Explicit ' frmInactiveShutDown v2.3 for MS Access from Peter's Software ' v3.0 Access 2010 64-bit compatibility ' v2.3 includes a "On Error GoTo 0" at the bottom of the timer routine ' ' Copyright: Peter's Software 2001-2010 :: http://www.peterssoftware.com ' ' Description: ' A form that monitors user activity and automatically shuts down the application after ' a specified period of inactivity. ' ' This module was created by: ' ' Peter's Software '
Finally, create a macro called "AutoExec" and set it to open the form (so that the countdown will start) but on hidden mode
To make it all work, do as follows:
- Visit File > Options > Current Database > and set a form to open when you open the database, for example a form called "Home"
- Create a macro that maximises a window form, then on the Home form, go to Design and set the onLoad action to that maximise macro
- Set the On Open of the form to the "AutoExec" macro, so that whenever the database is open, the shutdown form loads hidden in the background
Hope that helps!
London, 20 May 2020