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

Discussion in 'Microsoft Access Form Coding' started by Douglas J. Steele, Apr 3, 2009.

  1. Douglas J. Steele, Apr 3, 2009
    #1
    1. Advertisements

  2. Douglas J. Steele

    PJFry Guest

    RE: How to Capture the Value of "User Name" (or Initials) in Access 20

    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.
    --
    Regards,

    PJ
    Please rate this post using the vote buttons if it was helpful.



    "news.microsoft.com" wrote:

    > What VBA code do I use to determine the "User Name" or "Initials" of the
    > user?
    >
    >
    >
     
    PJFry, Apr 3, 2009
    #2
    1. Advertisements

  3. What VBA code do I use to determine the "User Name" or "Initials" of the
    user?
     
    news.microsoft.com, Apr 3, 2009
    #3
  4. 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".

    "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_gmail.com> wrote in message
    news:...
    > You can get their network ID using the code in
    > http://www.mvps.org/access/api/api0008.htm at "The Access Web"
    >
    > If the administrator has filled in the name when creating the ID, you can
    > use the code in http://www.mvps.org/access/api/api0066.htm
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no private e-mails, please)
    >
    >
    > "news.microsoft.com" <> wrote in message
    > news:ebX$...
    >> What VBA code do I use to determine the "User Name" or "Initials" of the
    >> user?
    >>

    >
    >
     
    news.microsoft.com, Apr 3, 2009
    #4
  5. Re: How to Capture the Value of "User Name" (or Initials) in Access 20

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

    "PJFry" <> wrote in message
    news:...
    > 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.
    > --
    > Regards,
    >
    > PJ
    > Please rate this post using the vote buttons if it was helpful.
    >
    >
    >
    > "news.microsoft.com" wrote:
    >
    >> What VBA code do I use to determine the "User Name" or "Initials" of the
    >> user?
    >>
    >>
    >>
     
    news.microsoft.com, Apr 4, 2009
    #5
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Initials

    Guest, Jul 22, 2005, in forum: Microsoft Access Form Coding
    Replies:
    4
    Views:
    211
    Guest
    Jul 23, 2005
  2. Ted via AccessMonster.com

    Programmatically insert initials at the end of each comment line

    Ted via AccessMonster.com, Oct 25, 2006, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    261
    Ted via AccessMonster.com
    Oct 25, 2006
  3. Mark Kubicki

    default value to be windowss user initials

    Mark Kubicki, Jan 30, 2008, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    225
    Yanick
    Jan 30, 2008
  4. L.A. Lawyer

    Capturing User Initials

    L.A. Lawyer, Nov 30, 2008, in forum: Microsoft Access Form Coding
    Replies:
    1
    Views:
    204
    Piet Linden
    Nov 30, 2008
  5. GD

    Auto initials & auto date not working right

    GD, Feb 23, 2009, in forum: Microsoft Access Form Coding
    Replies:
    0
    Views:
    235
Loading...

Share This Page