Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Aug 2003
    Location
    amsterdam, Netherlands
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    get user-id? (access 2000)

    hi
    Hope anyone can help me out with this

    I want Ms- Access to get the username by which the user is logged in
    and have it put as default in a field (when the user creates a new record)

    I 've been searching for the command and I assume is something in the same way as you would you use "NOW()"

    But I cant find the command

    anyone any idea?

    thanks ahead,

    Diederik

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: get user-id? (access 2000)

    If you mean the name under which the user logged in to a secured database, you can use Application.CurrentUser. In an unsecured database, that will always return Admin, however.

    Otherwise, you can use this code, to be put in a standard module:

    Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Public Function GetUser() As String
    Dim lpBuff As String * 255
    Dim ret As Long, UserName As String
    ret = GetUserName(lpBuff, 255)
    GetUser = Left(lpBuff, InStr(lpBuff, vbNullChar) - 1)
    End Function

    You can use this function in the Default Value property of a control on a form, like this:

    =GetUser()

    This will NOT work for a field in a table, you can't use custom functions there.

  3. #3
    Lounger
    Join Date
    Aug 2003
    Location
    amsterdam, Netherlands
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: get user-id? (access 2000)

    Thanks hans!

Posting Permissions

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