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

populating a field in Access with NT username? 1

Status
Not open for further replies.

joediga

Technical User
Jan 16, 2003
2
US
I'm using VBA to customize a form in MS Access 2000. I want to have the form autopopulate a field with the user's NT or local machine username when they make any change to any record. (So I can track who haas changed what.) I'm stuck. I can't figure out how to get the username into the form.
 
Hi Joediga,

There are two ways of doing this that I know of.

First, use a built in method:

example:

Text3 = Environ("username")

This will work on NT, Win2000, and XP. I am not sure about Win98.

Or you could use a function like:

Example:

*****start sample*****

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = &quot;&quot;
End If
End Function

******end sample********


Let me know if this does not answer what you need.

HTH


Have A Great Day!!!, [bigglasses]

Nathan
Senior Test Lead
 
Right on. I get satisfactory results with either method. As this is being developed for a Win2000 evironment, I'll probably just use the short code.

Thanks
 
I am trying to do the same thing with one of my forms how can you capture for Novell Login Names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top