Dear all,
For some reason, I need to use VBA to get the current NT user's name on Access 2000, how do i do that?
Thank you
PlayKid
Printable View
Dear all,
For some reason, I need to use VBA to get the current NT user's name on Access 2000, how do i do that?
Thank you
PlayKid
The easiest way would beCode:Msgbox Environ("UserName")
Thank you so much...
You are the best.
That assumes the Access username is the same as the NT user name. I know mine isn't. Use the GetUserName API.
Put this at the top of a module.
Paste this in the same module.Code:Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Use it like thisCode:Public Function GetNTName() As String
Dim sUser As String
sUser = String(255, Chr$(0))
GetUserName sUser, 255
sUser = Left$(sUser, InStr(sUser, Chr$(0)) - 1)
GetNTName = sUser
End Function
Code:Sub Useage()
MsgBox GetNTName()
End Sub
The code that I have posted does not pdisplay the Access user name. It displays the OS UserName. Environ function displays all the Environment Variables set on a particular PC and as UserName is one of the Enviornment Variables, so we can use this Function to get the NTUserName.Quote:
Originally Posted by mikeyc1204
See my FAQ thread on getting the username for more detailed info. :)
http://www.vbforums.com/showthread.php?t=357723