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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing current user 1

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
When I open a form I need a text Box to show the current users name. I have some old VB from Office 2000 that no longer works. I am currently using 2013. I would like to set the text box to show the current user when the form is opened, probably using the Forms On Open event. I am on a network with many users but only one at a time should be in the DB. Thanks

 
It Worked - Fantastic. Question, what would happen if more than one user was in the DB? This should not occur but what would happen? Than

thanks again
 
You may also try:
[TT]
MsgBox Environ("USERNAME")[/TT]


---- Andy

There is a great need for a sarcasm font.
 
>You may also try:

With the caveat that the user can actually change that to anything they like ...

Another alternative is

[blue]
Code:
Msgbox CreateObject("WScript.Network").UserName
[/blue]

which essentially does the same thing as Duane's code

What both Duane and my code do - ultimately - is to return the username of the user logged into the (Windows) Session the call is made from.
 
Skip,

I know that the Environ is not a 'fool-prove' method, but how would the user change their UserName to show something else?


---- Andy

There is a great need for a sarcasm font.
 
Actually, in our office, the user cannot change his userID. My question to Duane was, what will his recommended - and implemented - code return it two of my users had the db open at the same time?
 
puforee said:
what would happen if more than one user was in the DB?
The control would display the network login of the user who has logged into the network on that PC.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
pforee said:
Actually, in our office, the user cannot change his userID

I was not suggesting that users can change their userID, I was suggesting that they can change environment variables.

Andrzejek said:
I know that the Environ is not a 'fool-prove' method, but how would the user change their UserName to show something else?

Given that a process' environment block is inherited from its parent, and given that launching an application from the shell means that it is the shell's environment block that is inherited, and that block is created at session startup, then it isn't obviously easy for normal users to change it (some VBA using the Shell object and its Environment property would do it in theory, but in practice there are some nuances that make this a little trickier than it should be ...). The easiest way to demonstrate it is simply to launch a command prompt, run [tt]Set USERNAME="A Demo"[/tt], and then launch Access from that command prompt (it will then inherit the command prompt's now-altered environment block). [tt]MsgBox Environ("UserName")[/tt] should now show "A Demo" no matter who is actually logged into the PC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top