Solved

Database timer to close the application after 5 minutes

Posted on 2006-11-14
2
352 Views
Last Modified: 2010-02-08
I am trying to find some code that I can plug into the background of my database so that
after 5 minutes of inactivity (or just five minutes) the dbase will close automatically.  I have
used timers on forms in the past and they work, but this dbase doesn't keep one specific form
open.

Any idea's?
0
Comment
Question by:perplexed71
  • 2
2 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17939320
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17939346
In case the link ever dies, and so for EE PAQness

How to Create the DetectIdleTime Form
1. Create a blank form that is not based on any table or query and name it DetectIdleTime.  

2. Set the following form properties:
OnTimer: [Event Procedure]
TimerInterval: 1000
NOTE: The TimerInterval setting indicates how often (in milliseconds) the application checks for user inactivity. A setting of 1000 equals 1 second.  

3. Enter the following code for the OnTimer property event procedure:

NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.  


    Sub Form_Timer()
         ' IDLEMINUTES determines how much idle time to wait for before
         ' running the IdleTimeDetected subroutine.
         Const IDLEMINUTES = 5

         Static PrevControlName As String
         Static PrevFormName As String
         Static ExpiredTime

         Dim ActiveFormName As String
         Dim ActiveControlName As String
         Dim ExpiredMinutes

         On Error Resume Next

         ' Get the active form and control name.

         ActiveFormName = Screen.ActiveForm.Name
         If Err Then
            ActiveFormName = "No Active Form"
            Err = 0
         End If

         ActiveControlName = Screen.ActiveControl.Name
            If Err Then
            ActiveControlName = "No Active Control"
            Err = 0
         End If

         ' Record the current active names and reset ExpiredTime if:
         '    1. They have not been recorded yet (code is running
         '       for the first time).
         '    2. The previous names are different than the current ones
         '       (the user has done something different during the timer
         '        interval).
         If (PrevControlName = "") Or (PrevFormName = "") _
           Or (ActiveFormName <> PrevFormName) _
           Or (ActiveControlName <> PrevControlName) Then
            PrevControlName = ActiveControlName
            PrevFormName = ActiveFormName
            ExpiredTime = 0
         Else
            ' ...otherwise the user was idle during the time interval, so
            ' increment the total expired time.
            ExpiredTime = ExpiredTime + Me.TimerInterval
         End If

         ' Does the total expired time exceed the IDLEMINUTES?
         ExpiredMinutes = (ExpiredTime / 1000) / 60
         If ExpiredMinutes >= IDLEMINUTES Then
            ' ...if so, then reset the expired time to zero...
            ExpiredTime = 0
            ' ...and call the IdleTimeDetected subroutine.
            IdleTimeDetected ExpiredMinutes
         End If
    End Sub


4. Create the following procedure in the form module:

   Sub IdleTimeDetected (ExpiredMinutes)
         Dim Msg As String
         Msg = "No user activity detected in the last "
         Msg = Msg & ExpiredMinutes & " minute(s)!"
         MsgBox Msg, 48
   End Sub

 

How to Use the DetectIdleTime Form
To hide the DetectIdleTime form when the application opens, create the following AutoExec macro:


Macro Name   Action
   ---------------------
   AutoExec     OpenForm

   AutoExec Actions
   ----------------------------
   OpenForm:
      Form Name: DetectIdleTime
      View: Form
      Filter Name:
      Where Condition:
      Data Mode: Edit
      Window Mode: Hidden


You can add code to the IdleTimeDetected procedure so that the procedure runs if there is no user activity for the amount of time specified in the IDLEMINUTES constant value. For example, you could have Microsoft Access quit with the following event procedure:

   Sub IdleTimeDetected (ExpiredMinutes)
      Application.Quit acSaveYes
   End Sub


0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question