closeing forms based on inactivity

johnlatona123

Innovator
Local time
Today, 01:40
Joined
Sep 20, 2011
Messages
85
I have a zillion forms in my database and I needed to develop an automated kill-switch of sorts to handle some specific user issues. I’m open to other ideas, but the main purpose is to close forms and even the database based on user inactivity. i do not want this to effect reports however.

I need the to close a form based on an on-timer event macro (which I think I have figured out), BUT I want the timer for each individual form to reset and pause if that particular form loses focus. So that could be set as a lost-focus event of some type. I need that forms timer to remain in the paused state until the form regains focus.

I then need to restart the on-timer event macro based upon a gain-focus event that continues until either A) the form loses focus again, or B) the timer completes and close the form

It seems my options for the lost focus and gain focus events are going to be limited to VBA, I am not sure it would be possible to set macros for this function.

any ideas?

please advise.

thanks!
 
that sounds exactly like what i need. though i am having trouble implementing that, ive been getting errors when trying to apply it.

Could someone please set that up in a 2010 DB and post it here?

thanks!
 
I've already got the same thing set up Aphrodite. Look in the sample forum. I have a new version that will be out soon too. The code I used for the feature you are looking for is straight from a sample I found online, though I can't find it now. There may be a references in the code though. Or you can just google "ms access idle users", something like that.
 
ok ive got the thing going, now i need to exclude reports that i have that refresh

idears?
 
my reports are running this:

Private Sub Report_Timer()
n = n + 1
Me.Requery
End Sub

this effectively refreshes my reports, and now i need to exclude reports from the inactivity code or somehow count the requey as user activity.

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


current code!
 
Firslty, wrap your code with
Code:
 your code here [ /code] ,minus that space before the /.  

Secondly, why refresh your reports?  I've never heard of anyone doing it.

Thirdly, why would a report refresh be considered user activity?  Why should that prevent the log out?
 
1) im not sure what you mean

2) my reports refresh to display real time data on television screens, my database acts like a functional production planning/management tool, and reports provided the only method to display all of what i wanted to display.

3) i need the reports to remain open whereas i want everything else open to results in the DB closing.

thanks for helping me out, this one is kinda frustrating.
 
When you post code do this:
Code:
 Your code here [ /code]  

will look like this:
[code] Your code here

Try this:
Code:
Option Compare Database
Sub Form_Timer()
   ' IDLEMINUTES determines how much idle time to wait for before
   ' running the IdleTimeDetected subroutine.
   Const IDLEMINUTES = 0.6
   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
 [COLOR="Red"]  Dim ActiveReportName as string
   ActiveReportName  = Screen.ActiveReport.Name
   If Err then 
      ActiveReportName=""
      Err=0
   End If[/COLOR]
   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)[COLOR="red"] or len(activereportname)>0 [/COLOR]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
Sub IdleTimeDetected(ExpiredMinutes)
   Application.Quit acSaveYes
End Sub

Please note I did not test this at all. But maybe it will help you.
 

Users who are viewing this thread

Back
Top Bottom