Track user log in and outs.

marknufc

Registered User.
Local time
Today, 09:42
Joined
Dec 12, 2012
Messages
25
Hi,

I want to be able to track users log-ins on my DB, basically when a user enters their username and password I want the the time they log in and their username recorded in table. I tried doing it from the the Helpdesk database found here: http://www.access-programmers.co.uk/forums/showthread.php?t=208935 but I cant get it to work.
 
Each user on a network will have a username and in access this is called through the Function
Code:
 Environ("Username")

A macro called Autoexec only runs when the db opens so use this piece of code to write the information to a table which we can call LogIns with the fields User; DateandTimeIN
names
Code:
Public Function UserLogIn()

Docmd.SetWarnings False
DoCmd.RunSQL ("INSERT INTO LogIns ( User, DateandTime ) SELECT '" & Environ("Username") & "' AS Who, Now AS [When];")

Docmd.SetWarnings True

End Function


If you wanted to record when they log out, you will have to design your application to have a close button and then Call another piece of code that will UPDATE this same table with new field called DateandTimeOut.

Code:
Private Function UserLogOut()

Docmd.SetWarnings False

Docmd.Runsql ("UPDATE UserLogIn SET UserLogIn.DateandTimeOUT = Now
WHERE (((UserLogIn.UserName)='" & Environ("Username") & "') AND (Not (UserLogIn.DateandTimeIN) Is Null));")

Docmd.SetWarnings True

End Function
 

Users who are viewing this thread

Back
Top Bottom