Friday, April 15, 2011

How to get logged-in user's name in Access vba?

I want to get the name of user who have logged-in ,in the access vba. What is the best way to get it


Duplicates of this question:

From stackoverflow
  • Try this:

    Function UserNameWindows() As String
         UserName = Environ("USERNAME")
    End Function
    
    Mitch Wheat : Bear in mind that this can be changed by users/applications...
  • Public Declare Function GetUserName Lib "advapi32.dll" 
        Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    

    ....

    Dim strLen As Long
    Dim strtmp As String * 256
    Dim strUserName As String
    
    strLen = 255
    GetUserName strtmp, strLen
    strUserName = Trim$(TrimNull(strtmp))
    

    Turns out question has been asked before: http://stackoverflow.com/questions/168659/how-can-i-get-the-currently-logged-in-windows-user-in-access-vba/168682

    Varun Mahajan : I didn't see that the question has been asked before. Thanks, anyways

0 comments:

Post a Comment