Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    36

    Unanswered: Obtaining Windows User ID

    Hi,

    I’d like to create a database (Access 97) that captures the Windows User ID when someone creates a new record on a form. I’ve put the code within a module as instructed but am not sure if it works properly.

    Have anyone got any ideas

    Thanks

    M
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2004
    Posts
    137
    Instead of the Code Module, why don't you just use the built-in function:
    Environ("UserName")

  3. #3
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Just FYI

    Environ("Username") gives you the system login ID.

    CurrentUser() gives you the Access login ID, which is not necessarily the system login ID.
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

  4. #4
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    I CANT BELIEVE IT!

    how could it be this simple! I spent ages and ages and in the end found a code that I thought would fix it but gave me the machine Id, then I spent more time looking at found this code:

    Option Compare Database

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




    WHAT A LONG AND DRAWN OUT PROCESS WHEN I COULD SIMPLY HAVE DONE Environ("UserName")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •