473,388 Members | 932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Detect idle time, shut database down

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
1 5800
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine...
6
by: Stephane Belzile | last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS unit in case of power failure? Thanks
2
by: Keith Wilby | last post by:
The link below: http://support.microsoft.com/default.aspx?scid=kb;en-us;128814 to the Microsoft KB "Detect Idle Time" article shows how to detect "idle" time. However, if a user is active but...
3
by: Law | last post by:
To all the VB master, i'm new baby in VB. I would like to get ur's advice on how to stop the application when user is not in use within 5 or 10mins? Hope to hear VB master soon. Tks, Law
1
by: John Gibson | last post by:
Hi, all. We are running PostgreSQL 7.2.2 (7.4.1 in a few weeks). We have a pesky legacy application which periodically leaves open idle connections. (I know... fix the application). In the...
8
by: Stefan Barlow | last post by:
On IIS 6, I've disabled idle timeouts and any app pool recycling other than the 29 hour timed recycle. I've disabled both on the app pool itself and on all app pools at the server level. I've...
33
by: ram.ragu | last post by:
hi i have problem to calculate idle time of cpu and if idle time is more then i have to shut down the system. can anyone tell me the idea to so that please
5
by: LG | last post by:
Hi, I have recently used the Microsoft that will detect idle time coding on my Access database and it works fine as long as you do not add any data or move from one form to another. As soon as...
5
by: Bubba | last post by:
Hi, We have HttpHandlers that can process requests for up to 50 minutes. Those HttpHandlers are running in an app domain inside the DefaultAppPool. We'd like the HttpHandlers to be able to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.