Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Access After Set Time Peroid 3

Status
Not open for further replies.

quig699

Technical User
Nov 7, 2006
42
0
6
US
We keep having issues where people stay logged in to databases for days and days. Because of this we can not go in and make updates when we need to. I was looking for a way to have the database shut down after a certain amount of time. Like maybe after 6 hours or 8 hours the database closes. Everything the user has access to are forms that let them enter records or run reports.

Any suggestions??

Thanks!! =)
AMY
 
Quick search found this, which I use regularly:

thread705-1012106

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Where would I put this code? The post is not too clear on this. I tried putting it in the On Timer section of the form but it did not close. Any suggestions?

Thank You
 
The first post is the one I use. The following is taken from my project where it works...

Create a form called frmDetectIdleTime
You can leave it completely blank as you will never see it.
Set the TimerInterval property of the form to 1000
In the OnTimer event put the code at the bottom of this post. You also need to change the CONST IDLEMINUTES = 5 line to the number of minutes you want.
Then, on your "main" form (the first form you have open or the primary form you use), put the following in the OnOpen event: DoCmd.OpenForm "frmDetectIdleTime", , , , , acHidden

The frmDetectIdleTime will be opened invisibily and run in the background. Every second it will see if there is activity. If so, it resets its timer. If there is no activity, it increments its timer. If the timer has reached the maximum, it closes the database.

That's about it. Good luck and let me know if you have any issues.


Code:
    ' IDLEMINUTES determines how much idle time to wait for before
    ' running the IdleTimeDetected subroutine.
    Const IDLEMINUTES = 5
    Static prevcontrolname As String
    Static prevformname 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
    If Err Then
       activeformname = "No Active Form"
       Err = 0
    End If
    activecontrolname = Screen.ActiveControl.Name
       If Err Then
       activecontrolname = "No Active Control"
       Err = 0
    End If
    
    ' 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 previous names are different than the current ones
    '       (the user has done something different during the timer
    '        interval).
    If (prevcontrolname = "") Or (prevformname = "") _
      Or (activeformname <> prevformname) _
      Or (activecontrolname <> prevcontrolname) Then
       prevcontrolname = activecontrolname
       prevformname = 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?
    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
       DoCmd.Quit
    End If

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Can this same code go into a form that will be visible and useable?
Thank You
 
More than likely...yes, but I personally would not do it. The primary reason is due to the OnTimer event. Since this will be firing off at a pretty short interval, it may affect performance on that form. I think it would cause flashes of controls and even possibly resetting your location on a continuous form...but I am not certain. Another strong reason NOT to put this on a used form is that it monitors ALL forms in the application for use...This makes it more of a GLOBAL setting/event and should not be restricted/utilized in a local scope.

Just my couple of pennies worth...hope it helps.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
THANK YOU SO MUCH!!! IT WORKED IT WORKED!!!!!
 
Great post mstrmage1768, worked like a charm for me also, another star is due.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top