Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detect idle time on twin screen systems

Status
Not open for further replies.

Snoopy098

Programmer
Aug 28, 2009
4
GB
First time on here - a newbee....
Desperate for some assistance.

I have an access 2003 based database which is used by a small team of people. I have recently added an auto closedown to the program (this is where i am having a problem). When writing the program at home it works on a single screen system, however some of the people using the program run on mutli screen systems (2 or even three screens).

The problem that I have is that the database closes correctly after the specified idle time if you remain on the one screen and just flick to another program however it trips up if you move onto one of the other screens. The reason for this is that the timer in the VBA is looking at inactivity on the active screen that the access database is on ....

hope that is a clear enough explanation....

Can anyone help me please
 
How are you detecting inactivity? It sounds unusual that you have VBA that is looking at an individual monitor, and not what I would expect by default - not that I'm quite sure what you mean by it.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi Tony...
Obviously I do not explain things very well.
The inactivity detection part has been taken from other suggestion.... they all have it working
Below I have copied and pasted the section.
I have also maked the section (between *******) on the line that it errors out on



Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 20

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)
'Dim Msg As String
'Msg = "No user activity detected in the last "
'Msg = Msg & ExpiredMinutes & " minute(s)!"
'MsgBox Msg, 48

DoCmd.OpenForm "frm_ExitNonUse"

End Sub


Then of course the next form pops up which notifies the user that there is 5 mins before they program closes due to inactivity....

As I say... the program works completly correctly if it is run on a single screen system. in fact i am running it now on my home system (1 screen) an No Errors.


 
>The reason for this is that the timer in the VBA is looking at inactivity

Actually the program isn't looking for inactivity at all; it is for watching whether the active form (or control) changes. Which isn't the most reliable or flexible approach. Did you have a look at the code in the link HughLerwill provided? It may prove more robust (although as written it does have a potential issue if you call it when you get too close to the rollover time for GetTickCount, although that only happens once every 49.7 days)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top