Results 1 to 6 of 6

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

  1. #1
    Hyperactive Member
    Join Date
    Sep 04
    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 05
    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
    Hyperactive Member
    Join Date
    Sep 04
    Posts
    484

    Re: Get the current NT user name...

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

  4. #4
    Lively Member
    Join Date
    Jun 05
    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 08:13 AM.

  5. #5
    Shared Member
    Join Date
    May 05
    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
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 01
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    59,465

    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 (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 PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •