Results 1 to 9 of 9
  1. #1
    OpsO is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    12

    Question CurrentUser()

    Any ideas on how to identify current user in Access 2007 file format?

  2. #2
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    try the following functionj
    -------------------
    Function getOSUserName() As String
    On Error GoTo Err_getOSUserName
    ' Geeft de login naam van Windows
    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
    getOSUserName = Left$(strUserName, lngLen - 1)
    Else
    getOSUserName = vbNullString
    End If

    Exit_Err_getOSUserName:
    Exit Function

    Err_getOSUserName:
    Call gsgErrorHandling
    Resume Exit_Err_getOSUserName

    End Function

    ------------------------------
    grNG

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Here's something that will work as is:

    http://www.mvps.org/access/api/api0008.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    OpsO is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    12

    Smile

    Worked like a charm! Thank you very much!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    I have the API saved as a module, but I do not know how to incororate it. Any chance you could help me out with it?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You simply call the function where you want the user name. To put it into a textbox:

    Me.TextboxName = fOSUserName()
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    thekruser is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    93
    It is apparent that:

    Private Sub Form_Load()
    Me.Text0 = fOSUserName()
    End Sub

    is incorrect.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This is working for me:

    Code:
    Private Sub Form_Load()
         Me.txtUserID = fOSUserName
    End Sub
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. CurrentUser dependent data in formular
    By Patience in forum Access
    Replies: 1
    Last Post: 05-11-2010, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums