Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jul 2007
    Location
    North Carolina, USA
    Posts
    71
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Access 2007 (Current User)

    I used to use Access 2000, now our office has upgraded to Access 2007. I was told that rather than having a separate user list internal to the database to pull Current User based on the login and password entered, I could use the Windows login information instead. Is there a different built in function that will pull the computer login information rather than the DB access login. When I use (Current User) now it simply enters Admin in the field since no user login information is in the new database.

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You are correct about CurrentUser.

    Here is another function that does what you want.

    Code:
    Public Function NetUser() As String
        Dim strName As String
        Dim strUserName As String
        Dim intPos As Integer
        strName = vbNullString
        strUserName = Space(25)
        If WNetGetUser(strName, strUserName, Len(strUserName)) = 0 Then
            intPos = InStr(strUserName, vbNullChar)
            NetUser = Left(strUserName, intPos - 1)
        Else
            NetUser = "-unknown-"
        End If
    End Function
    But you need to put this at the top of a general Module

    Code:
    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" _
        (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
    Regards
    John



  4. #3
    Star Lounger
    Join Date
    Jul 2007
    Location
    North Carolina, USA
    Posts
    71
    Thanks
    5
    Thanked 0 Times in 0 Posts
    John, Thank you for the quick response. When I was using the Current User option before, I set the form to auto fill Current User into the Recieved By field.

    Private Sub Form_Load()
    [ReceivedBy] = CurrentUser()
    End Sub

    Can you clarify where I would need to enter the first portion of the Code you sent and if changing [RecievedBy] = NetUser() would result in the user setting being the Windows login name vise the Access login "Admin".

    Thanks again.

  5. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,494
    Thanks
    3
    Thanked 42 Times in 42 Posts
    Since John is presumably sleeping, I'll chime in. You need to put the code into a new module, or an existing module that contains that sort of code. And the Declarations would go at the top of that module.

    There is however another option to continue using the Access User Security as long as you are still working with an .MDB file. You can still connect to your old workgoup file, but you can't do it from the menu. You have to open the VB window and on the command line run code to open the dialog box for setting the workgroup file. I'll see if I can find the exact syntax, but at the moment I'm travelling. You can probably find it with a search as well.

    Here's the code to activate the Workgroup Administrator
    Code:
    docmd.RunCommand acCmdWorkgroupAdministrator
    Last edited by WendellB; 2012-03-30 at 10:50. Reason: Add code to run Workgroup Administrator
    Wendell

  6. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,533
    Thanks
    0
    Thanked 23 Times in 23 Posts
    Doesn't this do the same?

    Environ$("Username")

  7. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Quote Originally Posted by patt View Post
    Doesn't this do the same?

    Environ$("Username")
    I think you are right Patt.
    Regards
    John



Tags for this Thread

Posting Permissions

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