Solved

Database timer to close the application after 5 minutes

Posted on 2006-11-14
2
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

752 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