Sign Off procedure

G

Guest

I need to right a Sign Off procedure to update a record when the user signs
off. The record structure is as follows:
ID Autonumber
UserID String
LogIn Date/Time
LogOff Date/Time

I already have a SignIn procedure that works as follows:
Function AddtoSignOnHistory()
On Error GoTo Err_AddtoSignonHistory
Dim strUser As String
Dim mydbase As Database
Dim rs As Recordset

Set mydbase = CurrentDb


Set rs = mydbase.OpenRecordset("tbl_SignOn")
strUser = Environ$("username")

rs.AddNew
rs![User] = strUser
rs![LogIn] = Now


rs.Update
rs.Close

Exit_AddtoSignonHistory:
Exit Function

Err_AddtoSignonHistory:
MsgBox Err.Description
Resume Exit_AddtoSignonHistory

End Function


My SignOff procedure should find the most recent record that matches the
UserID who is signing off and where Login is NotNull and LogOff is Null.
Any suggestions/sample code would be appreciated.
Thanks.
 
M

Marshall Barton

John said:
I need to right a Sign Off procedure to update a record when the user signs
off. The record structure is as follows:
ID Autonumber
UserID String
LogIn Date/Time
LogOff Date/Time

I already have a SignIn procedure that works as follows:
Function AddtoSignOnHistory()
On Error GoTo Err_AddtoSignonHistory
Dim strUser As String
Dim mydbase As Database
Dim rs As Recordset

Set mydbase = CurrentDb

Set rs = mydbase.OpenRecordset("tbl_SignOn")
strUser = Environ$("username")

rs.AddNew
rs![User] = strUser
rs![LogIn] = Now
rs.Update
rs.Close

My SignOff procedure should find the most recent record that matches the
UserID who is signing off and where Login is NotNull and LogOff is Null.


I would use a hidden text box on the always open form to
store the ID value of the record you added.

rs.AddNew
rs![User] = strUser
rs![LogIn] = Now
Me.txtLogID = rs!ID
rs.Update

Then the form's Unload event would simply be:
. . .
strSQL = "SELECT LogOff FROM tbl_SignOn" _
& "WHERE ID = " & Me.txtLogID
Set rs = mydbase.OpenRecordset(strSQL)
rs.Edit
rs!LogOff = Now
rs.Update
rs.Close
. . .

If you ever want to use this mechanism to lock out other
users, be sure to provide adequate error handling to deal
with the OpenRecordset failing because it is locked out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top