I'm attempting to use an api to get the username of the currently logged in Windows user. I've basically copied and pasted the function from Function to return Username
Here is the code that I'm using:
However, I'm getting an error message on line 14 that says
Run-time error '49':
Bad DLL calling convention
I looked it up in MSDN and found Bad DLL calling convention. I understand absolutely nothing in the page so I'm going to need help.
Here is the code that I'm using:
Code:
Declare Function GetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) Public Function fGetUserName() 'Get current Windows user name Dim strUser Dim s$, cnt&, dl& Dim max_String As Integer max_String = 30 cnt& = 199 s$ = String$(max_String, 1) dl& = GetUserName(s$, cnt) strUser = Trim$(Left$(s$, cnt)) strUser = UCase(Mid(strUser, 1, Len(strUser) - 1)) 'Get user ID Application.TempVars.Add "UserID", DLookup("EmployeeID", "tblEmployee", "Username = '" & strUser & "'") Debug.Print Application.TempVars("UserID").Value 'Get user type Application.TempVars.Add "UserType", DLookup("EmployeeType", "tblEmployee", "Username = '" & strUser & "'") Debug.Print Application.TempVars("UserType").Value End Function
Run-time error '49':
Bad DLL calling convention
I looked it up in MSDN and found Bad DLL calling convention. I understand absolutely nothing in the page so I'm going to need help.
Comment