MS Access Idle Timeout

MS Access Idle Timeout

MS Access Idle Timeout is a very useful feature to add it within any Microsoft Access program. You might ask how to detect user idle time or inactivity so as to close any opened Microsoft Access form after a period of time (session timeout).

The answer is very easy though. All what you need to do is to ensure that the opened form has its own timer interval and you set an event procedure on timer. You can set these codes on a hidden form or on your main form.

Setting Timer Interval

Personally, I prefer to set 10000 at the timer interval field so that the event procedure behind the “On Timer” will check for idle time every 10 seconds.

On Timer Procedure

First of all, I have created a form to enable the user to specify the idle time setting to match his need as required. The MS Access VBA code will check for idle time every 10 seconds. If any opened form got focused. The timer will reset to zero. Otherwise, it will continue counting until the total elapsed time reaches the specified time by the user. In this case, all opened forms will be closed and the sign-in form will pop up.

VBA Code

				
					Static OldControlName As String
Static OldFormName As String
Static ExpiredTime

Dim ActiveControlName As String
Dim ActiveFormName As String
Dim ExpiredMinutes
Dim TimeIdle As Integer

On Error Resume Next

ActiveControlName = Screen.ActiveControl.Name
ActiveFormName = Screen.ActiveForm.Name

TimeIdle = Nz(DLookup("UserIdle", "tblUser", "UserName='" & Me.UserName & "'"), 5)
TimeIdle = TimeIdle * 100

If (OldControlName = "") Or (OldFormName = "") _
Or (ActiveFormName <> OldFormName) _
Or (ActiveControlName <> OldControlName) Then
    OldControlName = ActiveControlName
    OldFormName = ActiveFormName
    ExpiredTime = 0
Else
    ExpiredTime = ExpiredTime + Me.TimerInterval
End If

ExpiredMinutes = (ExpiredTime / 1000)

If ExpiredMinutes >= TimeIdle Then
    ExpiredTime = 0
    DoCmd.OpenForm "frmLogOut", acNormal
End If
				
			
You can download an example of MS Access Idle Timeout Program here.

In addition, the downloadable file will also include the sign-In form. You can refer to our post for Microsoft Access Sign-In form here.

To use Microsoft Access Programs.
You’ll need to have Microsoft Office installed including the bundle of MS Access or to download the free Microsoft Access 2016 run-time.

Please check our Pro Microsoft Access Programs here.