|
-
Feb 1st, 2006, 08:26 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Get the current NT user name...
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
-
Feb 1st, 2006, 08:32 AM
#2
Re: Get the current NT user name...
The easiest way would be
Code:
Msgbox Environ("UserName")
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Feb 1st, 2006, 08:59 AM
#3
Thread Starter
Hyperactive Member
Re: Get the current NT user name...
Thank you so much...
You are the best.
-
Feb 1st, 2006, 09:09 AM
#4
Lively Member
Re: Get the current NT user name...
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.
Code:
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Paste this in the same module.
Code:
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
Use it like this
Code:
Sub Useage()
MsgBox GetNTName()
End Sub
Last edited by mikeyc1204; Feb 1st, 2006 at 09:13 AM.
-
Feb 2nd, 2006, 02:40 AM
#5
Re: Get the current NT user name...
 Originally Posted by mikeyc1204
That assumes the Access username is the same as the NT user name. I know mine isn't. Use the GetUserName API.
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.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Feb 2nd, 2006, 02:45 AM
#6
Re: [RESOLVED] Get the current NT user name...
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 (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • 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 i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|