Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2001
    Location
    Vienna
    Posts
    400

    Unanswered: get system user in Msaccess

    Is there a method to get the active systemuser on a windowssystem
    from within Access
    Last edited by eperich; 10-17-05 at 11:25.
    http://www.postgresql.org
    --Postgresql is the only kind of thing--

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a google for Dev Ashish's API system calls

  3. #3
    Join Date
    May 2004
    Posts
    65

    This is it

    Paste the following code in a new module and call the function fOSUserName.

    eg.
    call fOSUserName()
    or
    Msgbox fOSUserName

    '******************** Code Start **************************
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    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 = vbNullString
    End If
    End Function
    '******************** Code End **************************

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    This should also work:

    environ("username")
    Paul

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Don't trust environ for security realted infroamtion. It is veryeasily faked or modfieid. Its fine for directories paths and config info, but if you want the authentic network logon call the api.

    Environ varaibles can be overwritten, if the system is low on resources then the OD can discard values. Depending on your network system & startup script environ variables may or may not be set. In short you can't rely on them for secure info.

  6. #6
    Join Date
    Sep 2001
    Location
    Vienna
    Posts
    400
    thanks for the Code

    But I have one problem I have access 2003 on Winxp SP2
    If I enter this code in a new Nodule it cant compile

    it says compile error no Projekt or Library found

    at String$ which is very strange to me

    Do I miss something or do I have to activate something in msaccess for this?

    Regards Ewald Geschwinde



    Quote Originally Posted by gavinfm
    Paste the following code in a new module and call the function fOSUserName.


    '******************** Code Start **************************
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    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 = vbNullString
    End If
    End Function
    '******************** Code End **************************
    Last edited by eperich; 10-18-05 at 05:07.
    http://www.postgresql.org
    --Postgresql is the only kind of thing--

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If you are getting that message it usually indictaes that a library or reference is messed up. To resolve open a form or report in design mode, view the code window

    select tools | references
    make sure that
    the Visual Basic For Applications is checked
    the ms Access xx OBJECT LIBRARY is checked (xx is probably 11.0

    HTH

Posting Permissions

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