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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Logout of my Database

Status
Not open for further replies.

TJVFree

Technical User
Nov 22, 2010
236
US
I’ve been trying to get this Auto-Logout.mdb to work.

Problem I’m having is that it looks like it’s working on my end but doesn’t kick the users off, but it will close on my end.

What I’m expecting to happen:

If anyone is in a cretin database I should be able to open the database and click on the: Auto Logout Scan (Run Now) button. A popup for open at anyone’s computer that has the database open and warns then that it will be closing and then after 3 minutes it automatically closes all databases that are open.

What I’m seeing. I can open the database on my end and click the Auto Logout Scan (Run Now) button a popup will open every 30 -50 seconds warning me and then after 3 minutes it closes.

Can I please get some help either correcting my database of advice on a better way

Thank you
TCB


Code:
Step 1-

-Create a form named DetectIdleTime
-Place this code in the form's On Timer event...

Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait for before
         ' running the IdleTimeDetected subroutine.
         Const IDLEMINUTES = 15

         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
         End If
End Sub


Sub IdleTimeDetected(ExpiredMinutes)
         'Dim Msg As String
         'Msg = "No user activity detected in the last "
         'Msg = Msg & ExpiredMinutes & " minute(s)!"
         'MsgBox Msg, 48
         
         DoCmd.OpenForm "frm_ExitNonUse"
         
      End Sub


I have the Timer Interval at 5000 which means the form checks the control status every 5 seconds and sends a warning after 15 minutes idle time. Feel free to change this to what best suits your application. Once this form detects that idle time has been reached, it launches a warning form...


Step 2-

-Create a new form named frm_ExitNonUse. Insert a Label field on the form with the following message in large bold red font on yellow form background...a real attention getter if you know what I mean..."This application will automatically close in 5 minutes due to non-use. To reset timer, simply close this form."

-Insert a command button labelled "OK" named cmdOK and place this code in the button's On Click event procedure

Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click


    DoCmd.Close

Exit_cmdOK_Click:
    Exit Sub

Err_cmdOK_Click:
    MsgBox Err.Description
    Resume Exit_cmdOK_Click
    
End Sub


-Set this form's Timer Interval to 5000 to again every 5 seconds check the active control. 

-Place this code in the On Timer event procedure...


Private Sub Form_Timer()
' 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
         End If
End Sub

Sub IdleTimeDetected(ExpiredMinutes)
         'Dim Msg As String
         'Msg = "No user activity detected in the last "
         'Msg = Msg & ExpiredMinutes & " minute(s)!"
         'MsgBox Msg, 48
         
         Application.Quit acSaveYes
         
      End Sub


Step 4-

-Create a macro named AutoExec(this will automatically execute when the database is open) with the following properties...

Action - Select "OpenForm"
Form Name - enter "DetectIdleTime" without quotes
View - Form
Data Mode - Edit
Window Mode - Hidden


Here is what will happen...

1-On open database, the AutoExec macro will execute openning the form named "DetectIdleTime" in hidden mode.

2-This form has a built in event timer that checks the name of the active control every 5 seconds and saves that name for future comparison.

3-Every 5 seconds, if the active control has not changed, it increments the timer by the elapsed time until the total elapsed time equals IDLEMINUTES or 15 minutes in this case.

4-If the active control name has changed, that is, the user has changed focus of the active control, the timer is reset to 0

5-If 15 minutes of idle time have passed, the hidden form opens another form that warns the user that the database will close in this case in 5 minutes, then resets the timer.

6-The newly opened form has its own timer counting down to 5 minutes doing the same 5 second checks on the active control name. If no activity, the database closes automatically.
 
some more information about what I'm looking for:

I have one database that on our server that 5 people login to. Sometimes throughout the month I need then to logout so I can add, update ect.

Is there a simple code or way I can log everyone that’s logged into my database. I’ve seen code that will log people off if the database is split; I’m not ready to split the database.

I was thinking sometime like creating a hidden form and then do something to make the database close.

Any help would be appreciated
 
How are ya CoreyVl . . .

Have a look here thread705-79802

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Thanks everyone for the advice and help. Looks like I’ll need to wait until I split my database.

Thanks again
TCB
 
Thanks for all your help, I was able to get it to work my making a marco with a quit command
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top