Log user

R

Raj

Hello,
Is is possible to log the users ID and time and date when
they log in and out of a database? If so can some direct
me to code that will do this.
Thanks
 
S

Scott McDaniel

Do you use a startup form? If so, code in the Open event will allow you to
capture this information:

Add a table to your database, name it tblLog and add 3 fields: lngID
(Autonumber), strUser (Text), and dteDate (DateTime)

In the Open event of your startupform, add this code:

Currentdb.Execute "INSERT INTO tblLob(strUser, dteDate) VALUES('" &
CurrentUser & "',#" & Now() & "#)"

Note that if you are not using Access security, you'll have to use alternate
methods to determine the user. here's one example:
http://www.mvps.org/access/api/api0008.htm

If you use this function, the code above would change like this:

Currentdb.Execute "INSERT INTO tblLob(strUser, dteDate) VALUES('" & fsOSName
& "',#" & Now() & "#)"

--
Scott McDaniel
CS Computer Software
Visual Basic - Access - Sql Server - ASP

"Smash forehead on keyboard to continue ... "
 
R

Raj

Scott,
Thank you for the code it is working great. I have one
question for you though how difficult would it be to add
a column that would show "Log In" and "Log Out" the user
would like to have that add to running a report.
 
S

Scott McDaniel

You could add one more field to your tblLog: dteDateOut. Again, assuming you
have a startupform, run code like this in the Close event of the form:

Currentdb.Execute "UPDATE tblLog SET dteDateOut=" & Now() & " WHERE
strUser='" & CurrentUser & "' AND Is Null(dteDateOut) DESC"
--
Scott McDaniel
CS Computer Software
Visual Basic - Access - Sql Server - ASP

"Smash forehead on keyboard to continue ... "
 
R

Raj

Scott,
I keep getting and error when I try and run the code.. I
am new to coding and not sure what is going on..
Raj
 

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