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

Capture Windows Logon Username on an Access Form 1

Status
Not open for further replies.

GLackey

Programmer
Dec 17, 2003
9
US
Using Access 2003, I've tried some of the examples in the archives but I'm not having any luck. All I want to do is capture the logon name of the person using the computer and then post it on a form in an unbound text box. I tried the example:

*************
Private Sub fDisplayMe()

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

Debug.Print strMessage

End Sub
*************
and it works in the immediate window but I can't seem to call it and pop it into the text box.

Any suggestions?


 
Why not set the ControlSource of the textbox to:
=Environ("UserName")


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Tried that. It just comes up with #Name? on the form.
 
And this ?
=VBA.Environ("UserName")
Or create a public function:
Public Function getUserName() As String
getUserName = Environ("UserName")
End Function
And then, for the ControlSource:
=getUserName()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks!!! The function worked but the =vba.environ("username") didn't for some reason.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top