A family of Microsoft relational database management systems designed for ease of use.
I found the following code that works for a 1 minutes idle time.
http://www.access-programmers.co.uk/forums/archive/index.php/t-115829.html
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am looking for a way to close access if the user is idle for 5 minutes. I found this link to code that I cannot get to work. I am not a advanced user in VBA and any help would be greatly appreciated.
http://bb.dzsoundnirvana.com/viewtopic.php?f=4&t=60
If you want this to run when the database file is open then create a new macro with the name of "AutoExec". Set the action to "OpenForm" and the action arguments are:
Form Name:DetectIdleTime
View:Form
Filter Name: Leave blank
Where Condition: Leave blank
Data Mode:Edit
Window Mode:Hidden
Create a new module in modules with the name of "TimeForm" and copy and paste the following code.
Option Compare Database
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
Create a blank form in design view. You do not have to set any data sources etc. Copy and paste the following code and save the form as "DetectIdleTime". Set the time in minutes where it says "Const IDLEMINUTES = 5".
Option Compare Database
Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 5
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
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
I found the following code that works for a 1 minutes idle time.
http://www.access-programmers.co.uk/forums/archive/index.php/t-115829.html
I have used this code for a form, much simpler and does exactly what I need.
Closes the database after a set amount of idle time.
Just set the timer to 1000 and how long in seconds you want it to remain open if idle, then it closes after the specified time.
Code:
'General Declarations
Dim lgCounter As Long
__________________________________
'(In the detail events section)
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lgCounter = 0
End Sub
_____________________________________
'(In form events section)
Private Sub Form_Timer()
lgCounter = lgCounter + 1
'Enter the amount of seconds before you want the database to close, and set the form timer to 1000.
If lgCounter >= 60 Then
Application.Quit acQuitSaveAll
End If
End Sub
Or copy and paste the code below into your form :-)
Dim lgCounter As Long
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lgCounter = 0
End Sub
Private Sub Form_Timer()
lgCounter = lgCounter + 1
'Enter the amount of seconds allowed to be idle before the database closes here and set the form timer to 1000.
If lgCounter >= 60 Then
Application.Quit acQuitSaveAll
End If
End Sub
If not the above code, is there anything else we could use to close access if a use is ible for too long?