Force Close database after idle time

K

Karissa

Is there a way to forcibly close the database if somebody has been idle for
too long? I know I've seen some code for it, but it was in in Access 2000
and I have 97... I'm hoping for something that will automatically pop-up
after they've been idle for, say, 60 minutes with a count-down or message
stating "You have been idle for 60 minutes. This database will close in 5
minutes if you continue to be idle" and then close after the 5 minutes - is
this possible?
 
K

Klatuu

Here is how it is done:
You need a form that is open as long as the database is open. It can be
hidden.
Use the form Timer event to add to a static variable in the timer event
until the 60 minutes has passed, then close the database.
 
K

Karissa

Great - the log-in form is open the whole time.

New question - what is a form Timer event and a static variable?

(I am still learning - I am fabulous at copying code and manipulating it to
meet my needs, but not so much with creating it from scratch.)
 
K

Klatuu

The Timer event fires on a predetermined interval specified in the Timer
Interval property. Each second is 1000, so to check every second, you would
set the value to 1000. To check once a minute, the value is 60,000. You can
get more detail in VBA Help by searching on Timer Event and Timer Interval.

A Static variable is one which retains its value between calls to a Sub or
Function.
Ordinary variables lose their value once the Sub or Function in which they
are Dimmed is exited. Static variables retain their value until they are
changed or until the database is closed. Here is an example of how it might
work assuming you are checking once per minute:

Static lngWaitTime

If lngWaitTime > 60 Then
Docmd.Close
Else
lngWaitTime = lngWaitTime + 1
End If
 
K

Karissa

Great, it works!

My only problem now is that it does it even if the person is working; I only
want it to close down if they are idle.
 
J

John Spencer

Microsoft has the following which should also work with Access 97.

Detect User Idle Time or Inactivity in Access 2000

Check http://support.microsoft.com/kb/210297

================================================
AND a long while back John Viescas posted this:

John Viescas, author
"Running Microsoft Access 2000"
"SQL Queries for Mere Mortals"
http://www.viescas.com/

I've used a variation of this technique in a couple of applications. First,
define a Public integer variable (I called mine gintActive). Define a form
that opens Hidden in your Startup and put a 5 minute value (300000) in the
Timer property. Behind the form, put this code:

Private Sub Form_GotFocus()
' This form should NEVER get the focus
' Hide it if it does!

' First, try to put focus elsewhere
On Error Resume Next
Forms!frmMain.SetFocus '<= name of main "menu" form
DoEvents

' Then hide me
Me.Visible = False
End Sub

Private Sub Form_Timer()
' This routine fires every 5 minutes
' and updates Public variable gintActive
' When gintActive exceeds 24 (2 hours),
' this routine will warn and close the application.
' gintActive is set to zero in all form current events.

gintActive = gintActive + 1
If gintActive > 24 Then
gintActive = 0
' Open form with short timer warning of shutdown
' fdlgWarning does Application.Quit in 10 minutes
DoCmd.OpenForm "fdlgWarning"
End If

End Sub

In *EVERY* other form in your application, add this line in the form Current
event:
gintActive = 0 ' Reset the timeout

============================================================================
============================================================================
The following KnowledgeBase artice should get you started:

http://support.microsoft.com/default.aspx?scid=kb;en-us;210297
HOW TO: Detect User Idle Time or Inactivity in Access 2000
============================================================================
============================================================================

I got this code from rolf.gerlicher(at)gmx.de
You call IdleTime() and get the duration in tick from the last time the
Keyboard was pressed or mouse was moved.

I think http://support.microsoft.com/default.aspx?scid=kb;en-us;210297, if
Ms Access is not active application and user is working with another
application, it will consider idle time. Depend on your need, you can use one
of these two idle detection methods.


Private Type PLASTINPUTINFO
cbSize As Long
dwTime As Long
End Type

Private m_typPLII As PLASTINPUTINFO

Private Declare Function GetTickCount Lib "kernel32" () As Long

Public Function IdleTime() As Long
On Error GoTo IdleTime_ErrHandler
m_typPLII.dwTime = 0
m_typPLII.cbSize = Len(m_typPLII)

GetLastInputInfo m_typPLII

IdleTime = GetTickCount() - m_typPLII.dwTime

IdleTime_NormalExit:
Exit Function

IdleTime_ErrHandler:
MsgBox Err.Description & ". Error number = " & Err.Number & ". Error is in
IdleTime."
Resume IdleTime_NormalExit
End Function

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
K

Karissa

I tried that one and it closed it unless I was actually typing; is typing the
only way Access measures idle time? Because I have some reports that take a
while to run; my users do not always need to type but could spend an hour
looking at different reports.
 
J

John Spencer

You could set the public variable in the open event of the reports. Just like
you do in the gotfocus event of the forms or in the current event of the forms.

I've never done this, so I can't speak to the effectiveness or efficiency of
the process.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top