locked
creating a time out event RRS feed

  • Question

  • I am having problems with people not closing out the database when they are done with whatever they are doing.  Now this is causing a problem when I try to perform maintenance after hours and cannot open objects in design view.  Is there a way I can cause the database to close after a certain period of inactivity?

    Thanks, JS

    Wednesday, September 25, 2013 12:59 PM

Answers

  • Create a "DetectIdle" Form
    You need to have the AutoExec Macro start this Form in Hidden View prior to other Forms or if you have a startup Form, then call it from that Form
    Set the Timer Interval to 6000
    Create the following procedure in the OnTimer Event

    Option Compare Database
    Option Explicit
    
    Private Sub Form_Timer()
             Const IDLEMINUTES = 60
    
             Static PrevControlName As String
             Static PrevFormName As String
             Static ExpiredTime
    
             Dim ActiveFormName As String
             Dim ActiveControlName As String
             Dim ExpiredMinutes
    
             On Error Resume Next
    
             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
    
             If (PrevControlName = "") Or (PrevFormName = "") _
               Or (ActiveFormName <> PrevFormName) _
               Or (ActiveControlName <> PrevControlName) Then
                PrevControlName = ActiveControlName
                PrevFormName = ActiveFormName
                ExpiredTime = 0
             Else
                ExpiredTime = ExpiredTime + Me.TimerInterval
             End If
    
             ExpiredMinutes = (ExpiredTime / 1000) / 60
             If ExpiredMinutes >= IDLEMINUTES Then
                ExpiredTime = 0
                IdleTimeDetected ExpiredMinutes
             End If
    
    End Sub
    
    Sub IdleTimeDetected(ExpiredMinutes)
       With Screen.ActiveForm
          If Screen.ActiveForm.Dirty = True Then
          .Undo
          End If
          End With
       Application.Quit
    End Sub
    
    

    Hth

    Let us know if you need help with this set up.


    Chris Ward

    Wednesday, September 25, 2013 1:22 PM
  • There is a KB article for this: http://msdn.microsoft.com/en-us/library/office/bb243861%28v=office.12%29.aspx


    -Tom. Microsoft Access MVP

    Wednesday, September 25, 2013 1:23 PM

All replies

  • There are several ways to handle that. Here is what I do.

    Have a Detect Idle Time Form to periodically see if there has been changes to the Active Form has had changes in the specified time. If so then reset the timer. If not then Undo any unsaved changes and quit the db.

    Conversely you could save the changes before quit if that suits your needs.

    I'll post some example code.


    Chris Ward

    Wednesday, September 25, 2013 1:17 PM
  • Create a "DetectIdle" Form
    You need to have the AutoExec Macro start this Form in Hidden View prior to other Forms or if you have a startup Form, then call it from that Form
    Set the Timer Interval to 6000
    Create the following procedure in the OnTimer Event

    Option Compare Database
    Option Explicit
    
    Private Sub Form_Timer()
             Const IDLEMINUTES = 60
    
             Static PrevControlName As String
             Static PrevFormName As String
             Static ExpiredTime
    
             Dim ActiveFormName As String
             Dim ActiveControlName As String
             Dim ExpiredMinutes
    
             On Error Resume Next
    
             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
    
             If (PrevControlName = "") Or (PrevFormName = "") _
               Or (ActiveFormName <> PrevFormName) _
               Or (ActiveControlName <> PrevControlName) Then
                PrevControlName = ActiveControlName
                PrevFormName = ActiveFormName
                ExpiredTime = 0
             Else
                ExpiredTime = ExpiredTime + Me.TimerInterval
             End If
    
             ExpiredMinutes = (ExpiredTime / 1000) / 60
             If ExpiredMinutes >= IDLEMINUTES Then
                ExpiredTime = 0
                IdleTimeDetected ExpiredMinutes
             End If
    
    End Sub
    
    Sub IdleTimeDetected(ExpiredMinutes)
       With Screen.ActiveForm
          If Screen.ActiveForm.Dirty = True Then
          .Undo
          End If
          End With
       Application.Quit
    End Sub
    
    

    Hth

    Let us know if you need help with this set up.


    Chris Ward

    Wednesday, September 25, 2013 1:22 PM
  • There is a KB article for this: http://msdn.microsoft.com/en-us/library/office/bb243861%28v=office.12%29.aspx


    -Tom. Microsoft Access MVP

    Wednesday, September 25, 2013 1:23 PM