Recording logged in username (not workstation name) (1 Viewer)

cochese

Registered User.
Local time
Yesterday, 21:57
Joined
Feb 5, 2008
Messages
54
On this board I've found some really cool code for creating user login forms and tracking/auditing, however I can't find out how (if possible) to record the action of a logged in user name and not the logged in user's workstation name.

For example an Access database has a user called jdoe and this user is opening the database on a workstation with the username janetdoe and the computer name DS-J1D-DT. When the user enters a new record I want to record the Access log in username jdoe and not her workstation username or computer name.

The only way I can see this being done is when the user opens the database and logs in, a global variable is set to the user's login name, and then when the record is added the table's field uses the global variable's value. Is there another cleaner way?
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 18:57
Joined
Dec 21, 2005
Messages
1,582
Or you could just use

Environ$("Username")

whenever you need to retrieve the user's name.
 

cochese

Registered User.
Local time
Yesterday, 21:57
Joined
Feb 5, 2008
Messages
54
That tells me the computer's user name, not which user is logged into the access database.

I should also add that this is in Access 2007.
 
Last edited:

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 18:57
Joined
Dec 21, 2005
Messages
1,582
Really? I use that code and it returns the username of the logged in user: both in AC2K and AC2K7.
 

boblarson

Smeghead
Local time
Yesterday, 18:57
Joined
Jan 12, 2001
Messages
32,059
Really? I use that code and it returns the username of the logged in user: both in AC2K and AC2K7.

Craig - as noted by cochese, the Environ('username") is the COMPUTER login (also known as Network Login if the computer is connected to a domain).


Cochese: If you are using your own security you can just leave an unbound form open and hidden with the value in a text box. That can be less susceptible to losing a global variable if an unhandled error occurs.

Or if you are using Microsoft Access' User Level Securty then you can simply use

CurrentUser
 

cochese

Registered User.
Local time
Yesterday, 21:57
Joined
Feb 5, 2008
Messages
54
I'll have to explore the unbound form idea. I'm using 2007, which I thought got rid of the user security level stuff.
 

boblarson

Smeghead
Local time
Yesterday, 18:57
Joined
Jan 12, 2001
Messages
32,059
I'm using 2007, which I thought got rid of the user security level stuff.

It did, in the ACCDB/ACCDE/ACCDR format. It is still there for the older MDB/MDE format. But I would not use it if you can do something else or else you will probably hate it when you finally do have to remove it.
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 18:57
Joined
Dec 21, 2005
Messages
1,582
Sorry. Guess i misunderstood the question.
 

Minddumps

Registered User.
Local time
Yesterday, 21:57
Joined
Jul 5, 2011
Messages
73
... however I can't find out how (if possible) to record the action of a logged in user name and not the logged in user's workstation name...
I am using 2007 and have my own security set up from Dane Miller's Advanced Custom Password DB (allows button access using Groups of Users instead of having to grant access to every single user). I'm trying to accomplish the same thing as you in figuring out how to capture the user's log in ID from the Log-in info I implemented.

This being said, did you ever figure out how to add in the DB user's name instead of the environ usernames?
 

cochese

Registered User.
Local time
Yesterday, 21:57
Joined
Feb 5, 2008
Messages
54
I never did it exactly how I wanted/envisioned. I had to have the user log into the database (thus selecting their username). Then the username went into a hidden form (well, not their username, but the primary key for it). The hidden form was always opened and when records were made/changed it always pulled this info from the hidden form.
 

Minddumps

Registered User.
Local time
Yesterday, 21:57
Joined
Jul 5, 2011
Messages
73
Thanks for the info. Do you recall where you gathered the "how-to" to set all that up?
 

Users who are viewing this thread

Top Bottom