Originally Posted by
stildawn
...In excel I would use =Environs("Username")...
I've seen a number of posts, since the roll out of v2007, reporting that =Environs("Username") sometimes works, sometimes doesn't, even within a single database. I use a fairly simple function that I came across ages ago (sorry to say, I can't remember the source.)
In a Standard Module, paste this in:
Code:
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
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 = vbNullString
End If
End Function
Save the Module and name it anything except fOSUserName.
Then, in Form Design View, in the Default Value Property of the Control, use this
=fOSUserName()
Linq ;0)>
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007