473,513 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inactivity Detection in Access

NeoPa
32,557 Recognized Expert Moderator MVP
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 9992
twinnyfo
3,653 Recognized Expert Moderator Specialist
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,557 Recognized Expert Moderator MVP
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 Recognized Expert Moderator Expert
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,557 Recognized Expert Moderator MVP
Me too ;-)
Nov 10 '13 #5

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

Similar topics

0
2759
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
7203
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
4306
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
5237
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
3271
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
1787
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
1906
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
3320
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
4255
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
8181
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
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4754
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.