Full Version: Whos Logged In
UtterAccess Forums > Microsoft® Access > Access Forms
oxicottin
Hello, I’m wondering if someone has an example of a very basic "Who’s logged in" .mdb? I have searched and searched and had found a basic one (Which I wanted) and prettied it up a bit removed some buttons and added Timer events ect and added a progress bar ect but not sure if it would work or show the users who open my database? I wanted to implement it in my switchboard to display who had my DB open. Will this example work? Thanks!
HiTechCoach
Since this appears tp be a multi-user app, is your database split? It should be!

You current code will only work for the front end and there should never be more than one user.

If you change the code to work with a back end, you will need to make sure the you keep a persistent connection to the back-end from each of the front-end workstations. If not, once the front end closes all open table, they will appear as logged out, en though the front end is still open.

Just curious, how will this help the end user?
oxicottin
Will it work if its in a .mdb in one location? Thanks...
HiTechCoach
>Even if it would, I would never try it in a multi user environment.

Ourge you to read:
Sharing an Access Database

The good news is that the code you are using will require only one line to be changed to work with a split app.

The code's comments even say:


The lines of code to look at are :

CODE

' Get Path of current database.  Should substitute this code
' for an attached table path in a multi-user environment.
   Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
   sPath = dbCurrent.Name   ' <<<< change this to the back end's path
   dbCurrent.Close



To open a back end, you only have to change one line of code.

Something like:

sPath = "\\server\sharename\Backend.mdb"



Edited by: HiTechCoach on Mon Feb 25 12:15:20 EST 2008.

Edited by: HiTechCoach on Mon Feb 25 12:16:49 EST 2008.
oxicottin
Will do.... And thanks for the information!
HiTechCoach
You're welcome!
Glad we could assist. sad.gif
uarulez2.gif
oxicottin
Well, I tried it and it gives the PC number and says admin for everyone that opens the DB. Also it never refreshes the list every 10000. I wanted it to show the user name? The only way it clears the list is if everyone closes the DB. Any ideas? I have a welcome form that I use that captures the users name when they open the DB is there a way I can just use that and when they log off it takes there name from the box? Thanks!

99% of the time there is only one person in the database entering data. I just wanted a list to populate who had it open then when they close the db it removes thier name.
recall
I always log the movement of people in and out of my database.
On the login screen when they enter the database it runs the following code :
!--c1-->
CODE
Dim DAOdb As Database
Dim DAOrs As DAO.Recordset
Dim S as Variant
Set DAOdb = CurrentDb()
IS = "SELECT * FROM tblwhologgedin;"
Set DAOrs = DAOdb.OpenRecordset(S)
    
    With DAOrs
        .AddNew
        .Fields("who") = fOSUserName()
        .Fields("When") = Now
        .Fields("Loc") = CurrentProject.Path
        .Update
    End With
    
    DAOrs.Close
    DAOdb.Close
    Set S = Nothing

This logs in the user and logs their name, time & date of login and Location of their front end.
When the user logs off using a close button on the main menu (I've hidden the Access close button) it runs this code:
CODE
Dim DAOdb As Database
Dim DAOrs As DAO.Recordset
Dim S as Variant
Set DAOdb = CurrentDb()
S = "SELECT * FROM tblwhologgedin where [who] = '" & fOSUserName() & "';"
Set DAOrs = DAOdb.OpenRecordset(S)
    
    With DAOrs
        .Delete
    End With
    
    DAOrs.Close
    DAOdb.Close
    Set S = Nothing

This deletes them out of the tblwhologgedin table.
HAs you can see I use the fOSUserName() procedure as usernames because everyone has their own Citrix account, but if you had a secure login with username and password you could obviously replace the fOSUserName() with their login name.
Oalso write their details that shows me a full logon history for users using :
CODE
Dim DAOdb As Database
Dim DAOrs As DAO.Recordset
Dim S as Variant
Set DAOdb = CurrentDb()
S = "SELECT * FROM TblLogonHistory;"
Set DAOrs = DAOdb.OpenRecordset(S)
    
    With DAOrs
        .AddNew
        .Fields("WhoLoggedOn") = fOSUserName()
        .Fields("WhenLoggedOn") = Now
        .Update
    End With
    
    DAOrs.Close
    DAOdb.Close
    Set S = Nothing

Hope this all helps.
oxicottin
recall, I use the access close and not a custom close button so would I have to put the cose code in every forms close event? Also do you have a sample of the Whos on? Thanks!
recall
You'd only have to put the close code under a button on the main form because surely you'd want users to go back to the main menu before closing out of the database. If you wanted to run the code from each form just do a public procedure and call it from the different forms. I always disable the access close button on the application so I can have full control of users in the database. I've not got this in a small database, theiy're all in massive databases I run, but I'll have a look this afternoon to see if I can knock something up.
Thanks,
Richard.
oxicottin
Thanks Richard! I will try getting this working tonight at work and let you know of my progress....
Thanks,
Chad
oxicottin
Richard, I created a sample from the code you have given but you had mentioned using a public procedure. I havent figured out that yet but here is what I have so far.... Thanks!
oxicottin
Well I tried it at work and it works like a charm.... Thanks! thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.