How To Auto Update Logout Time in LoginLog Table when user is sudden removed their LA (1 Viewer)

arjun5381

Registered User.
Local time
Today, 06:27
Joined
May 10, 2016
Messages
32
Dear All,
I need your help on Access VBA 2007, How To system will automatically update Logout Time in LoginLog Table when user is sudden disconnected on Network Connection OR sudden removed LAN cable from their Laptop.
Below is my Login_Form VBA Code, here i am using Sub Form_Close() event and it is working fine when user is properly logout on this application.

If user sudden remove their network cable from laptop then this LoginLog_ID is always showing on Who’s Online Query because i have created Who’s Online Query based on LoginLog Table where LogOut Time is Null. Next time when he will again Login this Application, on Who’s Online Query will showing duplicate records on this user.

I have automated if any new task was came on TaskDetail Table then automatically allocate user who’s online against New Tasks, that scenario when user will not Logout this Application properly then this user will showing always as Online and system will always assign new tasks to this user continually.

In my Application i am not using Login sessions if required please suggest and also suggest how/where to use session in my application.

Public GlobalEmpCode As Variant
Public GlobalEmpName As Variant
Public GlobalLngLoginId As Long

Private Sub cmdLogin_Click()
Dim con As Object
Dim Rs As Object
Set con = Application.CurrentProject.Connection
Set Rs = CreateObject("ADODB.Recordset")

Rs.Open "select * from SRT_tblEmployees where lngEmpID='" & txtLoginID.Value & "' and strEmpPassword='" & txtPassword.Value & "'", con, 1, 3

If Rs.RecordCount > 0 Then
GlobalEmpCode = Rs.Fields("lngEmpID").Value
GlobalEmpName = Rs.Fields("strEmpName").Value

Dim rs2 As Object
Set rs2 = CurrentDb.OpenRecordset("SRT_tblLoginLog")
rs2.AddNew
rs2.Fields("Emp_ID") = GlobalEmpCode
rs2.Fields("Emp_Name") = GlobalEmpName
rs2.Fields("Login_Date") = Now()
rs2.Update
rs2.MoveFirst
DoEvents
rs2.MoveLast
GlobalLngLoginId = rs2(0)
rs2.Close
Set rs2 = Nothing

Else
If Rs.State = 1 Then Rs.Close
Set Rs = Nothing
Exit Sub
End If

End Sub



Private Sub Form_Close()
Dim RsL As DAO.Recordset
Set RsL = CurrentDb.OpenRecordset("SELECT * FROM SRT_tblLoginLog WHERE ID =" & GlobalLngLoginId)

If Not RsL.EOF And Not RsL.BOF Then
RsL.Edit
RsL.Fields("Logout_Date").Value = Now()
RsL.Update
RsL.Close
End If
Set RsL = Nothing
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:27
Joined
Feb 28, 2001
Messages
27,186
In essence, you cannot do what you just asked if this information is in a Back-End database. At MOST, you might be able to store this information somewhere on the front-end and do an after-the-fact update. However, this would be "iffy" at best.

Remember, with Access, you are executing code on the front end and the back end only responds to actions from the front end. If you lose the connection for ANY REASON AT ALL, there is no way to do anything on the front end that will affect anything in the back end. The only thing you really could do is update your session information with a "last time I did anything" timestamp. If the user exits, timestamp that event. If the user's connection dies, then you at least know the last time they finished anything but still would not know when their session died.

That is, there is no way to do this unless you develop a reliable method of telepathy...
 

Users who are viewing this thread

Top Bottom