>Private Sub tmrIdleDetect_Timer() >' IDLEMINUTES determines how much idle time to wait for before >' running the IdleTimeDetected subroutine. >Const IDLEMINUTES = 10 >Static strPrevControlName As String >Static strPrevFormName As String >Static sngExpiredTime As Single >Dim strActiveFormName As String >Dim strActiveControlName As String >Dim sngExpiredMinutes As Single > > 'Only effective between 10PM and 6AM > If Not (Now > CDate(DateSerial(Year(Date), Month(Date), Day(Date)) & " " & TimeSerial(22, 0, 0)) And _ > Now < CDate(DateSerial(Year(Date), Month(Date), Day(Date) + 1) & " " & TimeSerial(6, 0, 0))) _ > Then > Exit Sub > End If > > On Error Resume Next > > ' Get the active form and control name. > strActiveFormName = Screen.ActiveForm.Name > If Err.Number Then > strActiveFormName = "No Active Form" > Err.Clear > End If > strActiveControlName = Screen.ActiveControl.Name > If Err.Number Then > strActiveControlName = "No Active Control" > Err.Clear > 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 (strPrevControlName = "") Or _ > (strPrevFormName = "") Or _ > (strActiveFormName <> strPrevFormName) Or _ > (strActiveControlName <> strPrevControlName) _ > Then > strPrevControlName = strActiveControlName > strPrevFormName = strActiveFormName > sngExpiredTime = 0 > Else > ' ...otherwise the user was idle during the time interval, so > ' increment the total expired time. > sngExpiredTime = sngExpiredTime + tmrIdleDetect.Interval > End If > > ' Does the total expired time exceed the IDLEMINUTES? > sngExpiredMinutes = (sngExpiredTime / 1000) / 60 > If sngExpiredMinutes >= IDLEMINUTES Then End >End Sub > >Cool Eric, my thanks. I will be working this in very soon.
"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams