Solved Run Update-Query to edit a record from a select query? (1 Viewer)

rbaron

New member
Local time
Today, 16:59
Joined
May 20, 2020
Messages
6
Hi everyone!!!

I have a program we use at work, I work for the province's telephone company (I'm in Canada 'eh!? 😆😆).
I am tracking users, and what PC they are on, and when they log in and out, that way if I have to update I can just ask that person to log out.
I have some code run on the load and the unload and for the most part it works.

Sometimes tho, if the user exits in an abnormal way, the unload portion of the code doesn't execute, and there's just no timestamp placed in the 'logout time' field. So next time that PC or user logs in again, is now show kind of, that they're logged in twice because no logout was recorded.

I did a select query to find multiple instances of the same pc and username with logout field null. Now I wanted to run an update query on that select query to stamp a logout time in the first record of the 2, but it won't let me.

I kind of want something that runs when the program starts, checks if there;s other instances of PC_NAME with LOGOUT_TIME as null (this indicates a logout wasn't recorded) and automatically stamp the logout time on the first record.

I'm getting old and rusty, and I'm an amateur at best... can someone provide some guidance please and thanks!
 
Last edited:

rbaron

New member
Local time
Today, 16:59
Joined
May 20, 2020
Messages
6
Thanks all!! I think I figured it out on my own, just had to do some hard thinking.
Basically, I created another form... grabbed the current userid and pc name into 2 fields, then ran an update query on the table, based on those 2 fields.. THEN I run the normal login script. So, if an entry already exists before I run the login script, it stamps a logout time on it, then continue on with normal user logging.

I open the form as hidden, run the query, and close the form. user doesn't see anything.

I appreciate everyone who gave this some thought for me.
 
Last edited:

Micron

AWF VIP
Local time
Today, 18:59
Joined
Oct 20, 2018
Messages
2,667
Have done something similar, but just checked the table and if there, updated the record as part of my startup routine. However, I wasn't checking for user sessions so much as just setting up the environment as it pertained to that user. I wonder if in your case a person can log in from 2 different pcs's. Then what, if you're checking for both the user and time stamp values?

Welcome to the forum btw, fellow Cannuk. It didn't take you long to realize positive results from joining us!
 

rbaron

New member
Local time
Today, 16:59
Joined
May 20, 2020
Messages
6
Have done something similar, but just checked the table and if there, updated the record as part of my startup routine. However, I wasn't checking for user sessions so much as just setting up the environment as it pertained to that user. I wonder if in your case a person can log in from 2 different pcs's. Then what, if you're checking for both the user and time stamp values?

Welcome to the forum btw, fellow Cannuk. It didn't take you long to realize positive results from joining us!
Haha thanks!!! Ya just not thinking right. Was trying to update records once I had already logged the user in.. then checking for instances of multiple logins and trying to update the first record of the select query etc.... was NOT working.

Then it just occurred to me, to just run an update query as soon as someone opens the program on any record where:
logout = null
username = Environ("username")
PC = Environ("computername")

(A user can be logged in more than once, because they can be logged on at more than 1 PC. So have to check for both values).

Basically, I'm just checking the table first before I log them in - if anything found, timestamp the logout, THEN proceed with the regular login script. Works like a charm.
 
Last edited:

The_Doc_Man

Happy Retired Curmudgeon
Local time
Today, 17:59
Joined
Feb 28, 2001
Messages
16,760
The only time I worked on this, I took the approach that if the username was the same and the computername was the same and a record existed with no logout time and the login was greater than X minutes ago, I marked the entry in my audit log as closed 1 second before the entry for the current session. I also had a flag showing abnormal termination because I was looking for trends from dum-dum users who couldn't be relied upon to actually operate their assigned machines correctly. As to the "greater than X" I had to experiment with that, but then it hit me. The site's IT department had set a particular session timeout policy. So I just asked them what it was and make my X value that time plus 1 minute.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom