473,385 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

Inactivity Detection in Access

NeoPa
32,556 Expert Mod 16PB
Introduction

Many developers within Access need to be able to detect when the user has been inactive for a while. It's quite common to have a requirement to run something if/when the system's not been used for a certain length of time. Examples range from running action queries in order to update data, to closing the database, or even Access itself, when it hasn't been used for a while.


Approach

My approach, like a number of similar ones that can be found on the web, is to detect and log the state of the currently selected form and control on the screen. I go a little further though, and detect all the forms and reports that are open in the project. It's not unusual for users, particularly those who mainly do data entry, to end up in exactly the same objects every time they finish entering a record - thus giving the impression to code which just checks which objects (Form and Control) are currently selected, that there has been no activity between checks. For that reason it's important to check the current data in the current control too.

Since Twinnyfo's question - Problem with Inactivity Detection - it is also important to ensure that this process is run regularly throughout the period of detection. If the checking is suspended at any point then the results can be misleading.


Code

Expand|Select|Wrap|Line Numbers
  1. 'IdleSince() returns the time of the last detected activity.
  2. 'NB. Code must run live (Full speed - Not tracing) to capture data correctly.
  3. Public Function IdleSince(Optional ByVal blnSet As Boolean = False) As Date
  4.     Static strPrevState As String
  5.     Static datPrevious As Date
  6.     Dim strState As String
  7.     Dim objVar As Object
  8.  
  9.     On Error Resume Next
  10.     With Screen
  11.         strState = strState & "," & .ActiveDatasheet.NAME
  12.         strState = strState & "," & .ActiveDatasheet.SelTop
  13.         strState = strState & "," & .ActiveDatasheet.SelLeft
  14.         strState = strState & "," & .ActiveForm.NAME
  15.         strState = strState & "," & .ActiveReport.NAME
  16.         strState = strState & "," & .ActiveControl.NAME
  17.         strState = strState & "," & .ActiveControl.Text
  18.     End With
  19.     On Error GoTo 0
  20.     strState = strState & ";Forms"
  21.     For Each objVar In Forms
  22.         strState = strState & "," & objVar.NAME
  23.     Next objVar
  24.     strState = strState & ";Reports"
  25.     For Each objVar In Reports
  26.         strState = strState & "," & objVar.NAME
  27.     Next objVar
  28.     'If we pop up a new form to notify the user then strState will change -
  29.     '  even without human intervention - so we allow for this with blnSet.
  30.     If strState <> strPrevState Then
  31.         strPrevState = strState
  32.         If Not blnSet Then datPrevious = Now()
  33.     End If
  34.     IdleSince = datPrevious
  35. End Function
Expand|Select|Wrap|Line Numbers
  1. ...
  2. If Now() >= DateAdd("n", 420, IdleSince()) Then ...
Explanation of Code

This is about detecting inactivity, rather than how to handle inactivity when found, so the parameter (blnSet) is not too relevant. However, for the curious, it was added in order to enable the code to show a form on the screen to notify the user that there has been inactivity, and potentially warn them that the system will shut itself down within a set time unless activity is detected. Obviously, showing the form would lead the procedure to detect activity when run normally, so blnSet is provided as an override.

Code Block A
Lines 04 - 05 These variables remember the values from previous calls.
Lines 09 - 19 These register all that Screen has to say on what's what and where. Some of these lines may refer to objects that aren't set - hence the error handling around these lines.
Lines 20 - 27 These lines log any forms and reports that may be be open.
Lines 30 - 33 These save the current state if necessary.
Line 34 This returns the last time activity was detected.

Code Block A
This is how a call to this procedure could be used. In this case 420 is the number of minutes that you want to check for. When this criteria has been met you can run whatever code you want that depends on this length of inactivity.


Conclusion

While this doesn't detect mouse movements, or even keystrokes, made by the user, it does detect almost all situations where activity has occurred within an Access session.
Sep 29 '13 #1
4 9980
twinnyfo
3,653 Expert Mod 2GB
NeoPa,

I have some code that functions similarly, but looks completely differently at "idle" time, because it looks at the last user input, using a call to user32.dll.

However, my code does detect mouse movements and other keystrokes, whether or not they are within the Access environment. My goal is to shut Access if the workstation has been left unattended (thus closing all links to the network BE).

I guess an advantage of your code is that if a user is working in another application, Access can still recognize itself as being "idle". I can see some uses for that in some specific situations.

Very interesting approach, and, as usual, you have taught me something I can probably use in the future.

Thanks for the article!

Grace and Peace,
Twinnyfo
Nov 4 '13 #2
NeoPa
32,556 Expert Mod 16PB
My aim was to provide a specifically MS Access way to detect idleness.

I suspect that OS functions do indeed give greater power and control in this area, but many prefer to avoid going off-piste, as it were, for good reasons. Principal of which, to my mind, is that it leaves a more easily supported and maintained project, as many Access developers are very nervous about using OS features..

Don't get me wrong - I do use OS features sometimes, but I try strenuously to avoid them.
Nov 4 '13 #3
zmbd
5,501 Expert Mod 4TB
Neopa: ... Don't get me wrong - I do use OS features sometimes, but I try strenuously to avoid them ...
I second that!

and I have to have 20 characters to make a post.
Nov 6 '13 #4
NeoPa
32,556 Expert Mod 16PB
Me too ;-)
Nov 10 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Serial # 19781010 | last post by:
I have a multithreaded server - one thread / client. I have a client 1 connected to thread A, and a I have client 2 connected to thread B. After certain equal period of inactivity Client 1 sends a...
60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
2
by: James P. | last post by:
Hello experts out there, I would like my Access application automatically closes completely after 30 minutes of "No Activities" so we can save resource. If the user is still scrolling or...
14
by: Sonic | last post by:
I have an MDE file that is growing exponentially (from 3,900 KB to over 132,000 KB today). I am not saving data in this MDE, although I use a mix of offline and SQL tables for Read Only querying. ...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed...
0
by: Jonas Hei | last post by:
I need to implement a listener that listens on a certain UDP port. I am trying to use Socket.BeginReceiveFrom for this purpose. In this scenario the remote clients (hundreds of them) send most of...
4
by: Dominique Vandensteen | last post by:
I need to receive an event when a form has a certain time of inactivity. Deactivate and Activated events are not good enough. With these events I can't find out inactivity if the form is simply...
4
by: Dan | last post by:
Hi, I have a timer on a form (System.Windows.Forms.Timer - Framework 1.1) that is set to 60 seconds as sort an of inactivity monitor. If 60 seconds have elapsed without any user activity I want...
4
by: sconeek | last post by:
hi all, i am trying to implement a page re-direction after a certain amount of inactivity. can somebody please help me in this. i was thinking could i display a screensaver using JavaScript after...
8
by: kk_oop | last post by:
Hi. Any recommendations for memory leak detection tools for C++ running on Linux or Solaris? I'm interested in static (compile time) and runtime detection. It's for a large project. Thanks! ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.