Accessing UserName via VBA

J

John Parker

On a secured database using workgroups, how can I access
the name of the user that is logged on using VBA?
 
B

Bruce

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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top