JMongi
Active member
- Local time
- Yesterday, 21:40
- Joined
- Jan 6, 2021
- Messages
- 802
One of my login functions checks for any outstanding sessions still running on another computer. I just realized as time "keeps on slipping, slipping, slipping...into the future..." that my log file will get longer and longer and thus my Dlookup might start taking too long to run.
tblLoginSessions
LoginID
UserName
LoginEvent
LogoutEvent
ComputerName
Notes
Should I be concerned? If so, what can I do about it?
tblLoginSessions
LoginID
UserName
LoginEvent
LogoutEvent
ComputerName
Notes
Code:
Public Function SessionCheck() As Boolean
On Error GoTo ErrHandler
glProcName = "modUserControl Function SessionCheck"
'This function checks the session log for any open sessions from the user and handles any already open sessions.
'The default is to prevent the user from logging in so that the code must work correctly for login.
Dim strCriteria As String, strSQL As String
strCriteria = "UserName='" & modUserControl.DomainUsername & "' And LogoutEvent Is Null"
SessionCheck = False
Select Case True
Case DCount("LoginID", "tblLoginSessions", strCriteria) = 0
'No unclosed sessions
SessionCheck = True
Case DLookup("ComputerName", "tblLoginSessions", strCriteria) = modUserControl.ComputerName
'User is logged in on the same computer
'Close previous session
strSQL = "UPDATE tblLoginSessions " & _
" SET LogoutEvent =" & Now() & ", Notes = 'Abnormal Close' " & _
" WHERE UserName='" & modUserControl.DomainUsername & "' AND LogoutEvent Is Null AND ComputerName='" & modUserControl.ComputerName & "';"
Debug.Print strSQL
'CurrentDb.Execute strSQL
SessionCheck = True
Case DLookup("ComputerName", "tblLoginSessions", strCriteria) <> modUserControl.ComputerName
'User is already logged in on another computer
FormattedMsgBox "User " & modUserControl.DomainUsername & " is already logged in at workstation " & _
DLookup("ComputerName", "tblLoginSessions", strCriteria) & " " & "@User " & modUserControl.DomainUsername & _
" MUST logout from that computer before logging in again. @", vbCritical, "Already Logged In"
Case Else
'Something unaccounted for has happened
'Message about it
End Select
ExitHandler:
'Any additional code needed on error
Exit Function
ErrHandler:
Call ErrProcessor(glProcName)
GoTo ExitHandler
End Function
Should I be concerned? If so, what can I do about it?