PDA

View Full Version : Logging User Names In Access



garydp
10-30-2015, 02:09 AM
I have a password protected access .mdb file.

is there a way of logging who has opened the file and what time the file was opened when the password is entered?

I think that someone has somehow managed to work out the password and want to see who is logging on

the file is accessed by an excel spreadsheet by multiple users but I only want to see who has opened the file manually.

thanks

jonh
10-30-2015, 05:03 AM
Create a table 'log' with a field usr with 'indexed' property set to 'Yes (No Duplicates)'


add this code to a module



Public Function log()
On Error Resume Next
DBEngine(0)(0).Execute "insert into log (usr) values ('" & Environ("username") & "')"
End Function


create a macro called 'autoexec'
Action = RunCode
Arguments = log()


The log table will record names of anybody that opens the database.

InLaNoche
10-30-2015, 08:31 AM
nice. I assume that the macro is run on opening the db?

jonh
10-30-2015, 09:17 AM
A macro named autoexec will run automatically when you open the database - unless you hold down the shift key, so you kind of have to hope they don't know too much about Access.

InLaNoche
10-30-2015, 11:34 AM
Kool. In the past I have created a splash screen that would run the macros needed. Good to know.

garydp
10-31-2015, 01:54 AM
excellent, how to add to this to add the date and time?

Thanks

jonh
10-31-2015, 07:38 AM
Add your field and change the sql

"Insert into log (usr,yourdatefield) values ('" & environ("username" & "'), now())"

jonh
10-31-2015, 07:40 AM
It'll only record the first login though unless you make the user field not indexed.

SamT
10-31-2015, 10:30 AM
I changed the Thread Title for easier searching

garydp
11-03-2015, 02:11 AM
excellent thanks