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

  • Thread starter Douglas J. Steele
  • Start date
P

PJFry

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.
 
N

news.microsoft.com

What VBA code do I use to determine the "User Name" or "Initials" of the
user?
 
N

news.microsoft.com

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".
 
N

news.microsoft.com

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)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Capture User's Actual Name in Field 1
Creating a user usage log 1
SetTempVar 2
fOSUserName 17
After shell, how to close xcopy instance? 3
User ID's 3
combination of Keys like CTRL + W 3
Get User Login Name 10

Top