MS Access - FInd Out Who Is Logged On.

I am using the code in the below link.

http://www.fmsinc.com/MicrosoftAccess/monitor/user-roster.htm

The issue I am having is that it should be showing me the user who is logged in per the example below in field 1 but instead I am receiving Admin.

http://www.fmsinc.com/MicrosoftAccess/monitor/database-users.htm

I need to obtain the User.  Any ideas?
LVL 2
CipherISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
The user rooster only displays the users logged into using the old Access security system.

When it's not active, then every user is admin.

I never tried it, but you may try using some Win32 API programming to check who has opened the laccdb file.
Abhigyan SrivastavaCommented:
You need to use Win32 API to check the current logged in user.

You can also use Environ$("Username") to get the username.

Or you can try this below code:
 ' Declare for call to mpr.dll.
   Declare Function WNetGetUser Lib "mpr.dll" _
      Alias "WNetGetUserA" (ByVal lpName As String, _
      ByVal lpUserName As String, lpnLength As Long) As Long

   Const NoError = 0       'The Function call was successful

   Sub GetUserName()

      ' Buffer size for the return string.
      Const lpnLength As Integer = 255

      ' Get return buffer space.
      Dim status As Integer

      ' For getting user information.
      Dim lpName, lpUserName As String

      ' Assign the buffer size constant to lpUserName.
      lpUserName = Space$(lpnLength + 1)

      ' Get the log-on name of the person using product.
      status = WNetGetUser(lpName, lpUserName, lpnLength)

      ' See whether error occurred.
      If status = NoError Then
         ' This line removes the null character. Strings in C are null-
         ' terminated. Strings in Visual Basic are not null-terminated.
         ' The null character must be removed from the C strings to be used
         ' cleanly in Visual Basic.
         lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
      Else

         ' An error occurred.
         MsgBox "Unable to get the name."
         End
      End If

      ' Display the name of the person logged on to the machine.
      MsgBox "The person logged on this machine is: " & lpUserName

   End Sub

Open in new window

Rey Obrero (Capricorn1)Commented:
here is short code to get the user name

Function GetUserName() As String
  Dim oName As Object
  Set oName = CreateObject("WScript.Network")
  GetUserName = oName.UserName
  Set oName = Nothing
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You can't directly get the user name, all you can do is get the computer name.

 But there are a couple ways of seeing who's logged on remotely, but all require admin access.

 It's often better to build in your own logging and then go off that.  One way to do that is with this:

http://www.experts-exchange.com/articles/5328/Resource-locking-in-your-applications.html

 by setting a "user lock" when they start the app, then clear it when they log out.  Then anyone that has a current "user lock" is in the DB.   Not foolproof, but probably the simplest overall.

Jim.
PatHartmanCommented:
I switched to logging this myself once ULS was deprecated.  That was actually a good thing since I now get a list of active users even when the BE is not Jet/ACE.
The user logs in using a login form.  I update his employee record with login time.  The login form hides and opens the menu.  That makes the login form also the last form to close when the database closes and so it runs an update query to record the logout time.  Then the roster query selects all employees where the login time is > the logout time.  Occasionally, there is a failure due to Access not closing properly but otherwise, it works pretty well.  I don't need history so I elected to add the two fields to the employee record rather than create a new table.  I also added a count field which increments each time the user logs in.  This helps to determine the most active users since they are the ones to talk to when you are contemplating changes.
Rey Obrero (Capricorn1)Commented:
using a login form is already ancient history with all my applications.
 - this all started when users from a client is getting annoyed by the login process thru a login form.
now, users are silently logged-in to a table when they open the application.
when they logged out or the application was closed, it records the time for the particular user.
PatHartmanCommented:
You must not be creating applications that work with sensitive data.  But true, the login process can be silent in applications that don't contain sensitive data.
CipherISAuthor Commented:
THE laccdb file contains "admin" in it.  My configuration is an MS Access file connected to a centrally located MS Access file on a server.  I want to know who is connected to it.
Rey Obrero (Capricorn1)Commented:
<You must not be creating applications that work with sensitive data.  > that is not correct, you can do this even with the most sensitive info.
PatHartmanCommented:
Only if people NEVER walk away and leave their computers unattended.  If you have sensitive information, you don't want to simply use the logged in users credentials.  You want to make them use a logon screen.  My clients are very sensitive to HIPAA rules.

CiperIS,
There is a utility which I believe can be found on UtterAccess but I can't post a link because that violates EE policy.  Search there for "who is logged in".  You can change the view to see the credentials of the logged in user.  If you are not already a member, you will have to join.  It is free.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.