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

Windows user login

Status
Not open for further replies.

RandyMyers

IS-IT--Management
Apr 28, 2004
85
0
0
US
How can I have the current Windows user login automatically entered into a field on a form?
 
You may try to play with Environ("USERNAME")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
As a test I tried creating a quick form with a textbox and a button. The textbox name is name and on the click event of the button I put this code as a test:

Dim uname As String

uname = Environ("USERNAME")
Me.name = uname

This results in and error "The property is read-only and can't be set"

Any ideas?

Thanks for you help...
 
NEVER EVER use the reserved word name for ANYTHING you create.
If you insist to have a textbox named name:
Me.Controls("name") = uname

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, I had already figured this out. name is a reserved word so relabeling the field to name1 for example worked, therefore on the click event I put this code:

name1 = Environ("USERNAME")

Thanks for the responses.
 
Jklo is right. I use it with the netware login name as windows is set the same.

Never give up never give in.

There are no short cuts to anything worth doing :)
 
I find that Environ("USERNAME") will give me the computer name (in Win 2000, Access 2000), but if I use an unbound text box and for the record source put in =fOSUserName() it will give me the actual user name.
 
In Windows XP this returns the user name because on my computer for example, the computer name is the asset number but my login is my name. When I use this my name is inserted in the field.

I will experiment with your method also. If is is more reliable then all the better.
 
Ok, as a follow up. The fOSUserName() does not work if you are setting a user name to a bound field. For example, I have a field where the user who entered the record is stored. Therefore the field is bound to a record. Setting this field when a new record button is clicked using fOSUserName() does not work, however:

Me.RecBy = Environ("USERNAME")

does work. It appears as if the other method would work fine for an unbound, information field. The statement above inserts the user login name of the current user into the field and it is savced in teh record.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top