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
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")
Use [code] source code here[/code] tags when you post source code.
My Articles
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
Last edited by mikeyc1204; Feb 1st, 2006 at 08:13 AM.
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.Originally Posted by mikeyc1204
Use [code] source code here[/code] tags when you post source code.
My Articles
See my FAQ thread on getting the username for more detailed info.
http://www.vbforums.com/showthread.php?t=357723
VB/Office Guru™ (AKA: Gangsta Yoda™®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Star Wars Gangsta Rap • Reps & Rating Posts • VS.NET on Vista (New) • Multiple .NET Framework Versions (New) • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007