Solved

Database timer to close the application after 5 minutes

Posted on 2006-11-14
2
328 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now