Link to home
Start Free TrialLog in
Avatar of edrz01
edrz01Flag for United States of America

asked on

Need to extract full user name from advapi32.dll or netapi32.dll

I am developing an Access form that will display the current user Log-in ID and want to add the Full Name of that user. Is this possible?

Current code is as follows:
Option Explicit
Option Compare Database

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
                        (ByVal lpBuffer As String, nSize As Long) As Long
''''''''''Buffer User Log-In Name'''''''
Public Function txtUserName()
    Dim sBuffer As String
    Dim lSize As Long
    sBuffer = Space$(255)
    lSize = Len(sBuffer)
    Call GetUserName(sBuffer, lSize)
    If lSize > 0 Then
        txtUserName = Left$(sBuffer, lSize)
        txtUserName = Trim(Left(txtUserName, Len(txtUserName) - 1))
    Else
        txtUserName = vbNullString
    End If
End Function
Avatar of therealmongoose
therealmongoose
Flag of United Kingdom of Great Britain and Northern Ireland image

Use the VBA function Environ("UserName")

ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sonchoy
sonchoy

Avatar of edrz01

ASKER

I am able to retrieve the user Log In ID name, but not the full name of the user. I know we store that information in Active Directory, so I wasn't sure if any other information may be extracted. Although I have used to JimD's information to create another Module, I am getting debug faults when attempting to enter in a text box =WhoAmI()...not sure what I am doing wrong there.

The links that Sonchoy sent is some of the code I am already using to display the Users Log In name. When attempt to replicate the "long" code from the http://www.mvps.org/access/api/api0066.htm link, these lines are not recognized by Access 2003.

So I still attempting to figure out how to get the fullname from the users log in...
Avatar of edrz01

ASKER

Although the solution given has the coding I could use I didn't get any response to my last question. So at this time I am closing the question as I have decided to add a user table and include boolean fieldnames, account name and log-in name. An sql string was written to check the log in name to the database and list the user information stored in the table.

Thanks for your assistance anyway.