Accessing UserName via VBA

  • Thread starter Thread starter John Parker
  • Start date Start date
J

John Parker

On a secured database using workgroups, how can I access
the name of the user that is logged on using VBA?
 
I don't remember wher I got this:

In the Declarations section of VBA->

Declare Function GetUserName Lib "ADVAPI32.DLL"
Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long


Then write the function:

Function LogonUserName()
Dim S As String
Dim N As Long
Dim Res As Long

S = String$(200, 0)
N = 199
Res = GetUserName(S, N)
LogonUserName = Left(S, N - 1)


End Function

then:

User_id = LogonUserName
Returns the UserID of the current user..
 
Back
Top