AutoExec - check Environ("USERNAME")

billy2345

New member
Local time
Today, 06:18
Joined
Sep 20, 2007
Messages
4
I am trying to put together some code that will check the username upon opening the db.
 
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)
 
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
 
How is it that someone can change the username returned by Environ("UserName")?
 
It is a DOS system variable like PATH. For you to change into whatever you want.
 
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.
 
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.
 

Users who are viewing this thread

Back
Top Bottom