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

Need to pull network user name as a default on a form 2

Status
Not open for further replies.

beverlee

Instructor
Oct 8, 2002
61
US
I've searched the database and found a few suggestions but none of them seem to work. I want to set the default value for a textbox on a form to be equal to the user's network logon name. We are using WindowsXP Pro on the local machines, Windows 2003 on the server, and Access 2000. I tried Environ("UserName") but it produced an #Error# in the textbox. Any other ideas? Thanks!
 
Create the following function in a standard code module:
Code:
Public Function getWinUser() As String
getWinUser = Environ("UserName")
End Function

And now the DefaultValue of your TextBox:
=getWinUser()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

I tried your resonse and it worked as long as I was placing a test box on a form. However, I tried to do this on a report, and did not have any sucess. Is the code that you posted, only useable on a form?

thanks
Richard
 
how about directly setting the value of a control as Environ("UserName")?

ie, on load

Dim strUser as String
strUser = Environ("UserName")
Me.Controlname.Value = strUser

does this work?
 
In which module did you create the function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

I just went under Module and created a new module, copied your code and saved it as "getwinuser".

I then went into the detailed section of a report, and added an unbound text box and then set the control to =getwinuser()

Each time I run the report, now I get a msg box prompting me for getwinuser (the name of the text box).

thanks,

Richard
 
Change the name of the module.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top