By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 3,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

Detect idle time, shut database down

P: n/a
I am using Access 2002. I downloaded the forms sample database
FrmSmp97.mdb from Microsoft and used the following code in the timer
event of a hidden form in order to close a database if no activity was
detected. I have it set for one minute for testing purposes only.
However, my problem with this code is when the message box pops up and
says "No user activity detected...", you have to actually click the OK
button before the database shuts down. And instead of having just an
OK button, I would like to give the users the option of keeping the
database open if they are actually working in the database, but if no
one is there, I want the database to shut down without having to click
the OK button. Can someone help me modify this code to do this?
Thanks - JD

Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for 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 <> 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
Application.Quit acSaveYes
End Sub

Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Many thanks!

MGFoster wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't use a MsgBox. Instead, create a form that will be displayed in
place of the MsgBox. Place a Cancel button ("The application will close in 5 minutes if the Cancel button isn't clicked.") on the form. Set up a Timer event on the form that will close the db if the user hasn't
clicked the Cancel button after the stated interval.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQgKhe4echKqOuFEgEQJvlACfZAsd3RbQwDjMwu1t06DyQu 9XH4AAn0k1
uagA+hKJsAEzBcIJLD7VoX1r
=5rzV
-----END PGP SIGNATURE-----
jd****@yahoo.com wrote:
I am using Access 2002. I downloaded the forms sample database
FrmSmp97.mdb from Microsoft and used the following code in the timer event of a hidden form in order to close a database if no activity was detected. I have it set for one minute for testing purposes only.
However, my problem with this code is when the message box pops up and says "No user activity detected...", you have to actually click the OK button before the database shuts down. And instead of having just an OK button, I would like to give the users the option of keeping the
database open if they are actually working in the database, but if no one is there, I want the database to shut down without having to click the OK button. Can someone help me modify this code to do this?
Thanks - JD

Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for 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 <> 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
Application.Quit acSaveYes
End Sub


Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.