1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Automatic logout

Discussion in 'Business Applications' started by Irv1010, Oct 2, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. Irv1010

    Irv1010 Thread Starter

    Joined:
    Jul 20, 2008
    Messages:
    23
    Hi all

    I am trying to get my Access 2003 db to log inactive users off after a period of time. Having found something within microsoft support, I have been trying to implement it with no success. I have created a blank form called DetectIdleTime with the following properties:

    TimerInterval: 1000
    OnTimer: [Event Procedure]

    Option Compare Database
    Private Sub Form_Timer()
    ' IDLEMINUTES determines how much idle time to wait before running the IdleTimeDetected subroutine.
    Const IDLEMINUTES = 1
    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 <> 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
    Private Sub IdleTimeDetected(ExpiredMinutes)
    Application.Quit acQuitSaveAll
    End Sub

    I also created a Macro called AutoExec as follows:

    Action: Openform
    FormName: DetectIdleTime
    View: Form
    Data Mode: Edit
    Window Mode: Hidden

    My problem is that nothing happens even though I sit and wait for well over the 1 minute. Any ideas?
     
  2. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    If you add an Error trap instead of using "On error resume next" you will see that it is continually cycling through an error.
     
  3. Irv1010

    Irv1010 Thread Starter

    Joined:
    Jul 20, 2008
    Messages:
    23
    Many thanks for responding again.

    I really don't know what you mean by Error trap. Would it be possible for you to give me an example please?
     
  4. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    At the beginning of the Code where you have "On Error Resume Next" change it to
    On Error Goto ErrorCatch

    As the last lines before the "End Sub" insert

    Exit Sub ' quits procedure before encountering the Error routine

    ErrorCatch:
    MsgBox Err.Description

    You will find that it just keeps cycling through the same error message each time the On Timer event tries to run
     
  5. Irv1010

    Irv1010 Thread Starter

    Joined:
    Jul 20, 2008
    Messages:
    23
    Many thanks again

    However, it still isn't working and when I close my switchboard form, I get a message saying "You entered an expression that requires a form to be the active window" this message keeps coming back every 2 seconds.
     
  6. OBP

    OBP

    Joined:
    Mar 8, 2005
    Messages:
    19,895
    Sorry , I didn't mean that it would Fix it, just tell you why it wasn't working.
    I will try and take a look at it later to see if I can see what is wrong.
    MS and MS help quite often provide VBA code that doesn't work
     
  7. Irv1010

    Irv1010 Thread Starter

    Joined:
    Jul 20, 2008
    Messages:
    23
    Many thanks. I'll put the db away to bed until I hear back from you. (I could do with a rest from it).
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/755392

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice