Hey Im curious where I am going wrong with this. I currently have it in a model labeled sessions and it is not saving anything. Am I supposed to call the session with cmd_Login_Click? I am not sure how to do this if I do have to. Where else might I be going wrong?
Option Compare Database
Public LngLoginId As Long
Function LogMeIn(sUser As Long)
'/Go to the users table and record that the user has logged in
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 1
Rs.Update
End If
Rs.Close
Set Rs = Nothing
End Function
Function LogMeOff(sUser As Long)
'/Go to the users table and record that the user has logged out
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 0
Rs.Update
End If
Rs.Close
Set Rs = Nothing
End Function
Function CreateSession(WhoAmi As Long)
'/This function records the details regarding the login details of the person
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("StoredLogins")
Rs.AddNew
Rs.Fields("AgentLoginID").Value = StrLoginName
Rs.Fields("DateTImeLogin").Value = Now()
Rs.Update
'/Next get the autonumber and store it to a public variable that will be used to
'/identify this session.
'/This id is used when user logs off to close this session.
Rs.MoveFirst
DoEvents
Rs.MoveLast
LngLoginId = Rs(0)
Rs.Close
Set Rs = Nothing
End Function
Function CloseSession()
'This closes the open session
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM StoredLogins WHERE SessionID =" & LngLoginId)
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("DateTimeLogout").Value = Now()
Rs.Update
Rs.Close
End If
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & LngUserID)
'Flag user as being logged out
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 0
Rs.Update
Rs.Close
End If
Set Rs = Nothing
End Function
Option Compare Database
Public LngLoginId As Long
Function LogMeIn(sUser As Long)
'/Go to the users table and record that the user has logged in
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 1
Rs.Update
End If
Rs.Close
Set Rs = Nothing
End Function
Function LogMeOff(sUser As Long)
'/Go to the users table and record that the user has logged out
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & sUser)
If Not Rs.EOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 0
Rs.Update
End If
Rs.Close
Set Rs = Nothing
End Function
Function CreateSession(WhoAmi As Long)
'/This function records the details regarding the login details of the person
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("StoredLogins")
Rs.AddNew
Rs.Fields("AgentLoginID").Value = StrLoginName
Rs.Fields("DateTImeLogin").Value = Now()
Rs.Update
'/Next get the autonumber and store it to a public variable that will be used to
'/identify this session.
'/This id is used when user logs off to close this session.
Rs.MoveFirst
DoEvents
Rs.MoveLast
LngLoginId = Rs(0)
Rs.Close
Set Rs = Nothing
End Function
Function CloseSession()
'This closes the open session
Dim Rs As DAO.Recordset
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM StoredLogins WHERE SessionID =" & LngLoginId)
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("DateTimeLogout").Value = Now()
Rs.Update
Rs.Close
End If
Set Rs = CurrentDb.OpenRecordset("SELECT * FROM [Logins] WHERE AgentLoginID =" & LngUserID)
'Flag user as being logged out
If Not Rs.EOF And Not Rs.BOF Then
Rs.Edit
Rs.Fields("LoggedIn").Value = 0
Rs.Update
Rs.Close
End If
Set Rs = Nothing
End Function