How to Capture the Value of "User Name" (or Initials) in Access 2007

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
Do you mean the person logged into the workstation? If so, create a new
module and paste this in:

'Used for grabbing the network name
Private Declare Function apiGetUserName _
Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As
Long
'Grabs the users network ID
Function fOSUserName() As String
On Error GoTo fOSUserName_Err

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 = ""
End If


fOSUserName_Exit:
Exit Function

fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function

Any time you need to record the network name, use the fOSUserName().

Post back if you need something different.
 
What VBA code do I use to determine the "User Name" or "Initials" of the
user?
 
Thanks, but. . . .

In retrospect, I was not clear: I am asking for the "User Name" and
"Initials" that are in Access 2007 itself, not the network name.

This is under Access Options, "personalize your copy of Microsoft Office".
 
This works but returns "Administrator" (I am using WinXP and Access 2007).
This is not particularly helpful on my network where all of the computers
have administrator.

How do I locate a more useful name (such as the "User Name" and "Initials"
inside of Access)?
 
Back
Top