Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inactivity (A2k)

    The following code taken from the Microsoft examples detects idle time if a user has not changed forms or control.
    The code resides on a user form and kicks in after an amount of time.
    The code works great, and opens the frmImages form as it should.
    But.

    On my timer form I have added a text box just to try the example and the timer still kicks in if I am entering data.
    This is obviously what I don't need.
    Which would be the best way to edit the code so it realises I am inputting data and delay the timer until I have stopped ??

    Option Compare Database
    Sub IdleTimeDetected(ExpiredMinutes)
    DoCmd.OpenForm "frmImages"
    End Sub
    Private Sub Form_Timer()
    ' IDLEMINUTES determines how much idle time to wait for before
    ' running the IdleTimeDetected subroutine.
    Const IDLEMINUTES = 0.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 / 100) / 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

  2. #2
    4 Star Lounger SteveH's Avatar
    Join Date
    Jan 2001
    Location
    Chelsea, Gtr London, United Kingdom
    Posts
    587
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inactivity (A2k)

    Off the top of my head without testing -
    Change the scope of ExpiredTime to a module level variable.
    Use the change event of the textbox to reset ExpiredTime to 0
    Steve H
    IT Lecturer/Access Developer
    O2K SR3/O2010; Win7Pro

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inactivity (A2k)

    Thanks Steve.
    The thought had already crossed my mind to code the text box to reset to 0, but.
    If I'm correct, this cannot be enforced until the user has either exited,saved.
    So the timer may kick in half way thru input.

    Please correct me if I'm wrong.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inactivity (A2k)

    Hi Dave,

    The On Change event mentioned by Steve occurs every time the user changes the contents of the text box by typing or deleting. In this, it is different from the Before Update, After Update and On Exit events, which occur when the user has finished updating the contents. So the timer won't kick in while the user is typing, unless (s)he types a character and then goes out to get a fresh brew before typing the next character.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inactivity (A2k)

    Hans
    I tried:
    ExpiredTime = 0
    In the On Change event of the text and the timer still kicks in.
    Maybe my elapsed time is too short !!
    I set it so short for programming purposes only.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Inactivity (A2k)

    Dave,

    Steve also mentioned that you had to make ExpiredTime into a module level variable. In the code in the first post in this thread it is declared within the Form_Timer event procedure:

    Private Sub Form_Timer()
    ...
    Static ExpiredTime
    ...

    If you want to set it to 0 in another routine, it must be defined outside Form_Timer. So remove the line Static ExpiredTime, and add a new line at the top of the module:

    Private ExpiredTime

    (You can't declare it as Static at this level)

    PS: Judging from the code, you still haven't set the default to Option Explicit...

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inactivity (A2k)

    Steve, Hans

    <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •