Inactivity timeout function

kit_sune

Registered User.
Local time
Today, 09:15
Joined
Aug 19, 2013
Messages
88
I'm trying to come up with a function that can track how long a user of the DB has been inactive for, and once it reaches a determined limit, it would save and close the DB. At the moment I'm just playing around with a test database.

I have a form with a button on it (Command0 - I didn't rename it)

The idea behind what I have below is that the main form is supposed to autoload when the database is opened. Once it loads, a timer script runs in the background that first initializes the inactivity limit in minutes and seconds - testing with 1 minute for the time being.

I use a text box at the moment to hold the current "Timer" value, that gets updated when the form is loaded, as well as whenever a button is pressed through VBA.

Then a loop script runs until the time limit is hit and then it kicks off the rest of the script, which is currently having a message box pop up saying "Time reached."

Code:
Option Compare Database

Private Sub Form_Load()

Dim timeout_mins As Double
Dim timeout_secs As Double
    timeout_mins = 1
    timeout_secs = timeout_mins * 60
    Me!Last_Time = Timer
    Do
        DoEvents
        Loop Until (Timer - Me!Last_Time) >= timeout_secs
    MsgBox "Time reached.", vbOKOnly
End Sub


Private Sub Command0_Click()

Dim time_Out As Integer
    time_Out = Timer - Me!Last_Time
    Me!Last_Time = Timer
    MsgBox "I've been inactive for " & time_Out & " seconds.", vbCritical

End Sub


The problem I'm having is as follows:
When the DB is opened, if I try to have the form pre-load, or if I try to open it, it freezes the DB until the timeout limit (1 minute) has been reached. However, if I first open it in design view, and then switch to form view, it displays as I would want it to, and I can use my button(s).

Also, I haven't looked up what the function to close the database is yet.

Thanks for any advice!
~Kit

Edit:

Actually, I found a command to close the database. I'm afraid this might not save the data before it closes though...
Code:
    MsgBox "Time reached.", vbOKOnly
    RunCommand acCmdCloseDatabase
 
Last edited:

Users who are viewing this thread

Back
Top Bottom