Question : VBA - Get UserName

I read the following question

http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_24604365.html

I was just wondering if there is a specific library or reference that I need to include, because I cannot get the function ENVIRON("UserName") to work?

Answer : VBA - Get UserName

try this codes

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


from   http://www.mvps.org/access/api/api0008.htm

Random Solutions  
 
programming4us programming4us