Quit Database

MiAs

Registered User.
Local time
Today, 07:28
Joined
Oct 25, 2004
Messages
49
I have set up a Quit Database macro using the 'On Timer' property for a form, as the database is used on a network causing conflict problems when entering data and open on two or more machines which may be idle.
Is it possible to make this quit after a period of timed inactivity?
 
I tried this and it didn't work

I have a startup search form and a editing/entry form. I did not touch the db for 30 minutes which was my time. It still did not close.
 
Not sure how you are using the code but you should have a form open in the hidden view so that user never sees it. Then place this code in the hidden form to close the db if there is not activity. To reset the idle time I reopen the hidden form when and where needed.

'this is how to open a form as hidden
DoCmd.OpenForm "YourFormName", , , , , acHidden

Code:
Option Compare Database
Option Explicit
    
Private Sub Form_Timer()
    
    Dim ExpiredMinutes
    
    Static ExpiredTime
    
    ' IDLEMINUTES determines how much idle time to wait for before running the IdleTimeDetected subroutine.
    Const IdleMinutes = 1 'Minutes
    
    ' Increment the total expired time.
    ExpiredTime = ExpiredTime + Me.TimerInterval
    
    ' 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

Private Function IdleTimeDetected(ExpiredMinutes)
   
'   MsgBox "No user activity detected in the last " & ExpiredMinutes & " minute(s)!", vbInformation, "Idle User"
   Application.Quit acQuitSaveNone
   
End Function

Private Sub Form_Open(Cancel As Integer)
            
    Static ExpiredTime
            
    ExpiredTime = 0
    
End Sub
 
It works

Actually put what you susggested in the Timer Procedure. Shouldn't that work the same instead of the old code in the link. Everything else including the Autoexec is the same as what was in link as well. This should work as well without adding anything including the zero assignment to the variable
 
It should work for only the users who are idle

This should only kill sessions which are idle correct. Say 4 are in there and 2 haven't worked on it in 30 minutes time. Then it would kill only those two sessions correct?
 
That is correct. Hopefully your db is split and the front end is installed locally on each users computer. Shared front ends will only lead to problems and possible database corruption.

I noticed your location. My wife spent a night in your towns hospital five years ago when she was ill while we were vacationing at Corolla [Outer Banks]. We were thankful that we did not have to travel any further at the time for a hospital.
 
Glad

Glad we could be there for you. I will be testing this some more. Has some potential.
 

Users who are viewing this thread

Back
Top Bottom