View Full Version : AutoExec - check Environ("USERNAME")


billy2345
09-20-2007, 05:52 AM
I am trying to put together some code that will check the username upon opening the db.

John_W
09-20-2007, 06:10 AM
The CurrentUser method should do it.

Example
The following example obtains the name of the current user and displays it in a dialog box.

MsgBox("The current user is: " & CurrentUser)

boblarson
09-20-2007, 06:38 AM
The CurrentUser method should do it.

Example
The following example obtains the name of the current user and displays it in a dialog box.

MsgBox("The current user is: " & CurrentUser)

CurrentUser ONLY works if you have secured the database using MS Access Security - otherwise all it returns is ADMIN.

You can use Environ("username") but some people don't like it because it can be changed by users (although most users wouldn't have a clue as to how to do so).

You can also use the API listed here:

http://www.mvps.org/access/api/api0008.htm

odin1701
09-20-2007, 07:10 AM
How is it that someone can change the username returned by Environ("UserName")?

Guus2005
09-20-2007, 07:14 AM
It is a DOS system variable like PATH. For you to change into whatever you want.

odin1701
09-20-2007, 07:37 AM
It is a DOS system variable like PATH. For you to change into whatever you want.

Okay, but how is this done?

Could I add UserName to the Environmental Variables in the system properties dialog, and put whatever username I want and that would override what windows does?

If that could be done, you could open the front end but you wouldn't have access to the network resource without a proper username and password so the front end couldn't find the back end so there wouldn't be anything you could do in it, assuming things are properly setup.

Technically, you could change what username the API procedure gets by just logging into a computer you control with a username that you create - but again without proper network access to the data, that really doesn't do you any good.

Guus2005
09-20-2007, 11:32 PM
Did you already followed the link from boblarson?

I am using similar code and it works for me. I don't use the Environmental Variables for the obvious reasons that users can change them.