Results 1 to 11 of 11
  1. #1
    mb1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Location
    Mississippi
    Posts
    5

    Finding network username of DB user.

    I've got several Access 2010 databases running on Windows 7. I'm able to find the computer name when someone is in the database. I can also get the Access username. I'd like to be able to get the network username of anyone in an Access database.

    Thank you in advance.

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Search on the Environ variables. The login ID is Environ("username") - if that is what you a re looking for.

  3. #3
    mb1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Location
    Mississippi
    Posts
    5
    I can use Environ("username") for my own computer. I need to figure out how to code where the computer name is used to find the user on another computer. For example,
    Comp#.Environ("username") if possible.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Looking around the net I didn't find anything to post for you. You can do your own search and see if any work for you. Altho another option would be to log users who are using the database, add a record to a log table each time the database is opened with a timestamp, and a time-out when they quit.

  5. #5
    mb1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Location
    Mississippi
    Posts
    5
    Thanks for searching. I have the table solution. What I'd like to do is something like: https://support.microsoft.com/en-us/...-microsoft-jet where I can cntl + g and then write the function name to show the machine number and the network number.

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not sure what you mean by "I have the table solution" - a login table would carry all this information.

    Otherwise try that code and see if it gives you what you are looking for.

  7. #7
    mb1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Location
    Mississippi
    Posts
    5
    I already have the code where the user/machine/time stamp are written to a table. The code I linked to does not give the network username. I only get the machine and the Access username.

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What is the difference between an Access username and a network username? If you can get it for your own computer, why can't you get it for anyone and store it on the table? Generally when databases require user security the Environ("username") is used to determine the user.

  9. #9
    mb1 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2017
    Location
    Mississippi
    Posts
    5
    I need the network username because some of the Access databases don't have usernames set up. I don't want a table involved. I want to adapt the code mentioned above. My need is to figure out the code to pull Environ("username") from another computer.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    Here is a function from mvps.org called fOSUserName



    Here is another method
    from Experts-Exchange https://www.experts-exchange.com/que...s-db-open.html
    by Ray Obero
    the easiest way is
    right click on the .laccdb
    open with ms Word
    select read only
    select Plain text

    you will see
    computer name user computer name user


    If these aren't what you are looking for, then provide more details/specifics.

  11. #11
    Forbes's Avatar
    Forbes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    133
    Save this Module
    Code:
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    
    Function UserNameWindows() As String
       
        Dim lngLen As Long
        Dim strBuffer As String
       
        Const dhcMaxUserName = 255
       
        strBuffer = Space(dhcMaxUserName)
        lngLen = dhcMaxUserName
        If CBool(GetUserName(strBuffer, lngLen)) Then
            UserNameWindows = Left$(strBuffer, lngLen - 1)
        Else
            UserNameWindows = ""
        End If
    End Function
    
    
    'Sub test()
    'MsgBox UserNameWindows
    'End Sub
    To call the current network pcs username use:

    Code:
    =UserNameWindows()
    If you wanted to use it as a login function on a form:

    Code:
    Private Sub Command4_Click()
    Dim rs As Recordset
    Dim strSQL As String
    Dim strPassword As String
    Dim strUserName As String
    On Error Resume Next
    strUserName = Username.Value
    strPassword = Password.Value
        Set db = CurrentDb
        strSQL = "SELECT fldPassword FROM tblUsers WHERE fldUsername='" & strUserName & "'"
        Set rs = db.OpenRecordset(strSQL)
        If rs.RecordCount > 0 Then
            If rs.Fields(0) <> strPassword Then
                MsgBox "You typed wrong password. Try again.", vbOKOnly, "Warning!"
            Else
                Me.Visible = False
                DoCmd.OpenForm "frmHome", acNormal
            End If
        Else
            MsgBox "You typed wrong username or password. Try again.", vbOKCancel, "Warning!"
            Password.SetFocus
        End If
    End Sub
    From here you can manipulate a populated list of current users, however, if the system is virtual.. you cannot see other users unless it has been allowed by an admin. I use this as a login method by locking the username box on the login screen so the db can only be accessed at that users PC, allowing different users different privileges with ease. I have been able to use the intermediate window in the past for this however ultimately gave up, not out of lack of information just the immense amount of trial and error I went through. You could even call the Shell to see active users in the Back End DB and echo that command to a text log, then if you really wanted to go further you can call the text in that log to a text box on a form. Again went through all of this many times and it became easier to use other means outside of the DB to view active users. Sorry if this doesn't help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Finding photos in network based on photo tags
    By LonghronJ in forum Modules
    Replies: 1
    Last Post: 02-18-2016, 04:02 PM
  2. Replies: 4
    Last Post: 11-28-2014, 01:43 AM
  3. How can I add username when user makes an update?
    By alexandervj in forum Access
    Replies: 14
    Last Post: 02-20-2014, 08:53 PM
  4. Replies: 6
    Last Post: 02-21-2013, 10:52 AM
  5. Replies: 5
    Last Post: 08-08-2012, 01:28 PM

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
  •  
Other Forums: Microsoft Office Forums