Auto Logout

writer2000

Registered User.
Local time
Yesterday, 21:02
Joined
Jun 16, 2015
Messages
20
The code below works great. The thing is, I need it to be modified a bit. I have 5 user types for this database. I wonder if there is a way to modify it so only certain user types will be logged out? Or, if can be set to only log out a user who is idle?

Option Compare Database
Option Explicit

Private Sub cmdHide_Click()
On Error GoTo Err_Handler
Me.Visible = False
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here
End Sub

Private Sub cmdRunNow_Click()
On Error GoTo Err_Handler
Me.TimerInterval = 9000
DoCmd.OpenForm "frmLogoutStatus"
Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here
End Sub

Private Sub Form_Timer()
On Error GoTo Err_Handler

Dim fLogout As Boolean

fLogout = DLookup("[LogOutAllUsers]", "[tblVersionServer]")
If fLogout = True Then
Me.TimerInterval = 180000
DoCmd.OpenForm "frmLogoutStatus"
Else
Me.TimerInterval = 30000
If IsLoaded("frmLogoutStatus") Then
DoCmd.Close acForm, "frmLogoutStatus"
End If
End If

Exit_Here:
Exit Sub
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here
End Sub

Public Function IsLoaded(ByVal sFormName As String) As Boolean
On Error GoTo Err_Handler

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, sFormName) <> conObjStateClosed Then
If Forms(sFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If

Exit_Here:
Exit Function
Err_Handler:
MsgBox Err.Description, vbExclamation, "Error"
Resume Exit_Here

End Function
 
Idle is your best option. It's what I use myself.
 
I'm assuming you didn't write that code! Anyway, here is a example:
Of course adapt to your situation. It would be called via your module.
PHP:
'Closes db in 30 seconds, form timer interval is  set to 1000
 
    Static StVarExpiredTime As Variant
  
    Dim varElapsed As Variant
    
    varElapsed = StVarExpiredTime
    
On Error Resume Next

If varElapsed >= 30000 Then 'if over 30 seconds without response, close db
        StVarExpiredTime = 0
        Application.quit acQuitSaveAll
    Else 'increase Expired Time
        StVarExpiredTime = StVarExpiredTime + Forms!YourFormNameHere.TimerInterval
    End If

HTH
 
No I didn't haha. I am still learning access (picked up Access 2010 VBA Programming Inside and Out-going through it now). I am able to do tables, forms, queries, and reports really well. I am still learning VBA and SQL. Definitely a novice. Thank you so much for your help!
 

Users who are viewing this thread

Back
Top Bottom