Solved User login / logoff activity in access 2016 (1 Viewer)

Ihk

Member
Local time
Today, 09:20
Joined
Apr 7, 2020
Messages
280
Hi,
In multiuser login system, activity is recorded (login or logoff) in an access table below.
I have following columns.

activity.JPG

Time stamp is the same column, but logon / logoff in different column.
How can I filter current logged in users, who have not yet logged of. I am not that much experience with queries.
If some one can help to filter.
Thanks
 

June7

AWF VIP
Local time
Yesterday, 23:20
Joined
Mar 9, 2014
Messages
5,466
I would not save data this way. I would save date/time into Login and Logoff fields of same record. I would have code find the user login record that does not have logoff value then populate with logoff date/time. Therefore when you want to know who did not log off just filter for records where Logoff Is Null.

Otherwise, try this: build aggregate query that counts Login and Logoff records for each user. Where count is not equal, someone has not logged out.

Really don't need two fields for activity type - just have 1 field with two possible values: Logon, Logoff.
 
Last edited:
  • Like
Reactions: Ihk

theDBguy

I’m here to help
Staff member
Local time
Today, 00:20
Joined
Oct 29, 2018
Messages
21,454
You could also try a Totals query to return the Max date for each user and then check if it's a Login.
 
  • Like
Reactions: Ihk

CJ_London

Super Moderator
Staff member
Local time
Today, 08:20
Joined
Feb 19, 2013
Messages
16,607
agree with other comments, just have one column to indicate login/off but with your current structure your query might be something like
Code:
SELECT UserIDD
FROM UsersActivity A INNER JOIN (SELECT UserIDD, max(timestamp) as Latest FROM UsersActivity GROUP BY UserIDD) AS L ON A.UserIDD=L.UserIDD AND A.timestamp=L.Latest
WHERE ActivityLogon is not null
 
  • Like
Reactions: Ihk

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:20
Joined
May 7, 2009
Messages
19,232
Code:
SELECT subQuery.UserIDD, "Currently Login" AS Status
FROM
(SELECT UsersActivity.UserIDD,
(SELECT MAX(TimeStamp) FROM UsersActivity AS T
    WHERE T.UserIDD = UsersActivity.UserIDD
    AND NOT (T.ActivityLogin Is Null)) AS MaxLogin,
(SELECT MAX(TimeStamp) FROM UsersActivity AS T
    WHERE T.UserIDD = UsersActivity.UserIDD
    AND NOT (T.ActivityLogoff Is Null)) AS MaxLogoff
FROM UsersActivity
GROUP BY UsersActivity.UserIDD)  AS subQuery
WHERE (((subQuery.MaxLogin)>Nz([subQuery].[MaxLogoff],1)));
 
  • Like
Reactions: Ihk

Ihk

Member
Local time
Today, 09:20
Joined
Apr 7, 2020
Messages
280
Code:
SELECT subQuery.UserIDD, "Currently Login" AS Status
FROM
(SELECT UsersActivity.UserIDD,
(SELECT MAX(TimeStamp) FROM UsersActivity AS T
    WHERE T.UserIDD = UsersActivity.UserIDD
    AND NOT (T.ActivityLogin Is Null)) AS MaxLogin,
(SELECT MAX(TimeStamp) FROM UsersActivity AS T
    WHERE T.UserIDD = UsersActivity.UserIDD
    AND NOT (T.ActivityLogoff Is Null)) AS MaxLogoff
FROM UsersActivity
GROUP BY UsersActivity.UserIDD)  AS subQuery
WHERE (((subQuery.MaxLogin)>Nz([subQuery].[MaxLogoff],1)));
I am very thankful, without any further change, this code worked perfectly. great love.
 

Users who are viewing this thread

Top Bottom