I used the code below that I foundonline for creating a timer that will close the DB when there is no activity,it works great with how it was designed looking for activity with a new form. However, with my DB it needs some adjusting as my DB has a single navigationform with multiple rows of tabs that the users click through for the informationthey are viewing. There are separate forms that they occasionally will select. With this the Active form does not change, thus I need a way for it to call on the active tab of the navigation form. I am still new to coding and I need someone to help me write this the correct way.
The way this code works is I have a form named Detectidle Time with the text fields txtOpenForm, txtMinutes, and with the below code in the Event On Timer with the Event Timer Interval = 1,000.
I am assuming I can create a new field (txtCurentTab) to store the name of the current tab in use called from the code below just like the current form is populated into the txtOpenForm. I have tried to write the code, however I feel like I am not telling it how to reference the current tab name correctly.
I have attached screenshots of the Detectidle Time form, andthe Navigation form that works 90% of my DB.
Code:
Option Compare Database
Private Sub Form_Timer()
' IdleMinute determines how much idle time to wait for before
' running the Idle Time Detected subroutine.
Static OldControlName As String
Static OldFormName 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
Me.txtOpenForm = ActiveFormName
ActiveControlName = Screen.ActiveControl.Name
' 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 old names are different than the current ones
' (the user has done something different during the interval).
If (OldControlName = "") Or (OldFormName = "") _
Or (ActiveFormName <> OldFormName) _
Or (ActiveControlName <> OldControlName) Then
OldControlName = ActiveControlName
OldFormName = 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?
'.......................................................CHANGE EXPIRED MINUTES TIME (ExpiredTime / 1000) / 60.........................
ExpiredMinutes = (ExpiredTime / 1000) / 60
Me.txtMinutes = ExpiredMinutes
' Me.txtMinutes = Format (ExpiredMinutes, "Standard")
'.......................................................CHANGE EXPIRED MINUTES TIME >= 10 Then.........................................
If ExpiredMinutes >= 10 Then
' then reset the expired time to zero...
ExpiredTime = 0
' ...quit application
MsgBox "No activity in last " & "10 minutes", vbCritical, "Terminate Program"
Application.Quit acSaveYes
End If
End Sub