Solved

Database timer to close the application after 5 minutes

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

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…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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 …

760 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

25 Experts available now in Live!

Get 1:1 Help Now