Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Shut down after inactive
Justin Langdon 
     
3 years ago
Is there a video on how to add a timer to the database that will shut it down after a predetermined amount of time has passed without activity?
Brent Rinehart  @Reply  
        
3 years ago
Justin came across your question, I needed something like this as well found something on the internet, It does seem to work but I would not be able to explain all the code so use at your own risk.

To create a timer event in Microsoft Access that shuts down the database if there is no activity for 10 minutes, you can follow these steps:
Open your Access database and open the form you want to monitor for activity.
Switch to the form's design view.

In the VBA editor, for the form insert the following code:

CODE-------------------------------------------------------------------------------------------------------------------------

Private lastActivityTime As Date
Private Const inactivityTimeout As Integer = 10 ' Timeout value in minutes

Private Sub Form_Timer()
    ' Check if the form has had any activity
    If DateDiff("n", lastActivityTime, Now) > inactivityTimeout Then
        ' No activity for the specified timeout, close the database
        DoCmd.Quit acQuitSaveNone
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Update the last activity time when the form is clicked or the mouse is moved
    lastActivityTime = Now
End Sub

Private Sub Form_Load()
    ' Initialize the last activity time when the form is loaded
    lastActivityTime = Now
    Me.TimerInterval = 60000 * 10 ' Set the timer interval to 10 minutes (60000 milliseconds * 10)
End Sub

CODE END ---------------------------------------------------------------------------------------------------------------------

Save the changes to the form's module and close the VBA editor.
Switch back to the form's design view.
In the form's property sheet, locate the "Timer Interval" property and set its value to 60000. This value represents the timer interval in milliseconds, so 60000 corresponds to 1 minute.

That's it! Now, whenever there is no activity on the form for 10 minutes (as defined by the inactivityTimeout constant), the database will automatically close. The Form_Timer event is triggered every minute, and if the time difference between the last activity and the current time exceeds the timeout value, the DoCmd.Quit command is executed to close the database without saving any changes.
Justin Langdon OP  @Reply  
     
3 years ago
Many thanks! I'll give this a try!
Gregory Clancey  @Reply  
    
3 years ago
This looks useful. Let's hope Rost makes it the topic of a TechHelp vid (if he'd not already done so).

"Live short, yet prosper"
             -- Mrs. Spock
Kevin Yip  @Reply  
     
3 years ago
Brent's method won't work unfortunately, because a form's MouseMove event only runs when you point the mouse to specific spots on the form, such as the record selector or scroll bar.  You can't count on the user to always move the mouse there.

One way to detect user idleness is to create a form specifically for detecting idle user activity in all the forms, instead of having to code this for every single form.

We need to define what idleness means, since different people may have different definitions.  Here is mine: if the *active form* and the *active control* BOTH remain the same for N seconds or minutes, that means the user isn't doing anything.  "Active" means having the focus.  If MyForm1 has the focus, and Textbox1 on the form has the focus, and that remains unchanged for N amount of time, that indicates an idle user -- because a non-idle user would be navigating and changing focus among the controls on the form, and/or changing focus among different forms.  And when idleness is detected, the clock starts ticking, until it reaches the time of expiration, or not.

That is the idea behind this article from Microsoft:

https://learn.microsoft.com/en-us/office/vba/access/concepts/miscellaneous/detect-user-idle-time-or-inactivity

This is, of course, not a perfect solution, because the user could be typing in the *same* textbox for a long time (such as in a big memo field), and would be treated as an idle user with the method above.
Gregory Clancey  @Reply  
    
3 years ago
It seems that your idea is like the device chess players use to end their turn. It is activated not by some mechanical assessment of activity on the playboard, but by an independent action of a player to mark his compliance with an agreed upon time allotment standard as well as to invite the opponent to begin their turn.
Kevin Yip  @Reply  
     
3 years ago
Naturally this depends on user action: user activity keeps the form active, and idleness starts the "countdown" to close the form.  The difference is that a chess timer clock (to use your analogy) does not reset the time to the beginning when the user resumes activity.
Gregory Clancey  @Reply  
    
3 years ago
Yes. Your point is well taking. I think I was actually working with the idea that the user takes some action -- say a button press or "parking area" for the mouse cursor -- to trigger a count. Then any subsequent activity (mouse movement, keypress, etc. . .) would be like the little plunge button on a stopwatch. No time measuring until the next deliberate "reset" action. Should the period "time out" then the DB goes dormant -- perhaps a colour change or translucent cover. Then even a password awakening may be a further security step. I can see more than one approach.
Kevin Yip  @Reply  
     
3 years ago
You can't rely on the user to "tell" the system he is idle.  The system has to detect user idleness on its own.  If the user has to press a "button" to become idle, he will never be idle, because he may never push the button.  This is the whole point of having an "automated" way to detect idleness.  It needs to work regardless of what the user does -- if the user simply stares at the Access forms but doesn't do a thing, the database will and should shut down.
Gregory Clancey  @Reply  
    
3 years ago
That makes sense. Why not a simple "no mouse movement" then -- or the automatic time countdown starting after each event triggered on the Form and then out of the loop until the next, say, input?
Kevin Yip  @Reply  
     
3 years ago
The user can tab around the form without having to use the mouse.  So the lack of mouse movement doesn't necessarily indicate idleness.  A form can be made without having a single event (i.e. no code).  So you can't count on form events either.  This is not an easy problem to solve, as I mentioned.  Even the workaround from Microsoft that I mentioned earlier doesn't perfectly detect idleness.
Gregory Clancey  @Reply  
    
3 years ago
Ah. Of course. I often use the tab key to advance the focus to the next input. I am slowly learning the art of "thinking outside the box." Thanks.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/1/2026 10:40:21 PM. PLT: 0s