Results 1 to 10 of 10
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieve the current user name (2000)

    I would like to be able to see who is using a database. I have the following code:

    Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpbuffer As String, _
    nSize As Long) As Long

    Function GetCurrentUserName() As String
    Dim strName As String
    Dim lngCharacters As Long
    Dim lngReturn As Long
    strName = Space(255)
    lngCharacters = 255
    lngReturn = GetUserName(strName, lngCharacters - 1)
    If lngReturn = 0 Then
    GetCurrentUserName = "Unable to retrieve name."
    Else
    GetCurrentUserName = Left(strName, lngCharacters)
    End If

    End Function

    When I type - ?GetCurrentUserName in the immediate window, I would like to see everyone's user name that is in the database. This code only shows mine. Is there a way to modify this code to show all users? Thanks for your help.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieve the current user name (2000)

    Francois

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieve the current user name (2000)

    See MSKB article How to determine who is logged on to a database by using Microsoft Jet UserRoster in Access 2000. This will give you a list of computer names of users logged into the database.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieve the current user name (2000)

    Francois,

    Those functions will tell you which users have been defined in the .mdw file, regardless of whether they are currently using the database.

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieve the current user name (2000)

    Right <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

    The function provided by Linda will return the windows username.
    Do your function return those names or only the names created and used by the User Level Security ?
    Francois

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Retrieve the current user name (2000)

    The code in the MSKB article I mentioned will list the computer names of users listed in the internal log Access keeps, plus some other information, such as whether they are currently logged in, and their Access login names. If the developer has set user-level security, the login names will be meaningful, but if user-level security has not been set up, everyone will be fhe default user Admin.

  7. #7
    5 Star Lounger
    Join Date
    Jan 2001
    Posts
    1,119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieve the current user name (2000)

    I don't have any security for this database. My code is a windows API function.

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Retrieve the current user name (2000)

    The code that Hans pointed out is the only way to do this, but the Roster returns the computer name, not the windows login, of each user. And no, there is no way to modify the code you posted to return what you are asking. You either have to use Access security or use the JetRoster to return computer names.
    Charlotte

  9. #9
    5 Star Lounger
    Join Date
    Apr 2003
    Location
    Hampshire, United Kingdom
    Posts
    602
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieve the current user name (2000)

    I have a database which does this. I have a table of users (which includes permissions etc.) containing a couple of extra fields: last login and last log-out. Whenever the database is opened, it displays a form, and the close event of the form closes the database; that way, the form is always open.

    When the form is loaded, I update the "last login", and when it's closed I update the "last log-out". Then I can see who's logged in by running a query showing which users' "last login" was AFTER their "last log-out".
    Waggers
    If at first you do succeed, you&#39;ve probably missed something.

  10. #10
    3 Star Lounger
    Join Date
    Jun 2001
    Location
    Salem, Oregon, USA
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Retrieve the current user name (2000)

    I do basically what Dave does. If you add to the code that you have so that it will send the user's name (and time of entry) to a table, and then make that code run at startup for all your users, you can query the table to find who is in (especially if you do like Dave and have exit times posted as well, in a closing code module). I have named my similar routines over time "Whos_in" and the Whosin table <g>.
    thx
    Pat

Posting Permissions

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