Results 1 to 6 of 6

Thread: [RESOLVED] Get the current NT user name...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    Resolved [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

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    484

    Re: Get the current NT user name...

    Thank you so much...
    You are the best.

  4. #4
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    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.

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Get the current NT user name...

    Quote 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

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width