Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference current user? 1

Status
Not open for further replies.

sqleptical

Programmer
Sep 26, 2001
112
US
I'm creating a form that users use to enter data into tables.

Each user has their name & initials associated with each respective license of MS Access 2000.

Is there a way to have the VBA code reference the user name when they hit the Submit button?

I'd like to use this to track who made each data entry without having the users select who they are from a combo box or have to type it into a text box.

Thanks!
 
This grab the logon name of the person.

Dim GetUser As String
GetUser = Environ("UserName")
 
Only if your environment happens to set that particular environment variable.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

sqleptical

If you have set user-level security, access built-in CurrentUser() function returns the user name used to log on
 
fNeily - that code is fine, provided that the network is based around a Microsoft Active Directory domain.

If you are working in a Novell NDS/eDirectory environment, use

Note that this code is known to work with the client up to 4.93 on Windows 2000 and Windows XP. I have not tested it with Windows Vista.

John
 
Thank you all for your help!

CurrentUser() returned 'Admin'

Dim GetUser As String
GetUser = Environ("UserName")

...returned the UserName I was looking for.

 
sqleptical - as well as fneily's comment about being able to change the contents of environment variables, they also are only populated on Windows NT family systems (NT, 2000, XP, Vista). The environment variables aren't set on Windows 9x systems (95, 98, Me) - although rare now in commercial systems, this is another consideration for using the API calls instead.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top