Rost provides a sophisticated bridge between low-level system calls and high-level database management to solve a critical security gap. This tutorial is a masterclass in extending the utility of legacy tools through precise technical workarounds.
Deep Dive
Voraussetzung
- Keine Daten verfügbar.
Nächste Schritte
- Keine Daten verfügbar.
Deep Dive
Are You There? Automatically Log Users Out After Inactivity in Microsoft Access, Part 4Hinzugefügt:
Welcome to another tech help video, brought to you by accesslearningzone.com.
I'm your instructor Richard Rost.
This is a completely unplanned part four of my Are You There series.
I wasn't originally planning to make part four in this three-part series, but several of you pointed out a really useful Windows API function that can tell you whether the user is actually still sitting at their computer.
Now, parts one through three, which if you haven't watched those, go watch those first and then come back.
But, those videos are for tracking activity inside your Access database.
And that's still the best way to tell whether the user is still actively working in your application.
But, what if they minimize Access and then go spend a half an hour answering email or browsing the web or watching some of my videos or working in Excel or whatever. From Access's perspective, they appear inactive even though they're still sitting right there at the keyboard.
Now, Windows keeps track of the last time the user touched the keyboard or moved the mouse anywhere on the computer.
So, with a couple of API calls, we can just ask Window for that Windows for that information and then find out exactly how many seconds the system has been idle.
All right, here I am in my tech help free template and yes, I'm in dark mode because it's at night and I'm using my cool dark mode stuff that I built.
Now, if you've never used the Windows API call before, don't panic.
Programming with API calls is a lot like driving a car. You don't need to understand how every piston and gear works under the hood. You just need to know where the gas pedal is and what it does. So, in this case, all you really need is one simple function called Get Idle Seconds.
Now, I'm going to create a module and I'm going to paste in here my code that I have in notepad. I'm going to go down it slowly so all you guys can get a good look at it.
And gold members, this will be in the code vault.
And I'm just going to save this real quick. We're going to call this the idle mod cuz it's tracking idle seconds from Windows.
And it's basically get idle seconds is the function we're going to use. It returns a long integer.
And it returns the number of seconds since the user last touched the keyboard or mouse. That's it. That's real simple.
No complicated setup, no forms, no classes, no extra references, just a simple Windows API call.
And again, you don't understand what all of this is doing, but I'm just going to give you the real quick overview. At the top of the module, this thing here, okay? This creates a structure called last input info. It's just a container that Windows uses to send back information to us. It includes the size of the structure and a timestamp representing the last input event.
All right, that's this guy.
Next, we declare two Windows API functions. And these are just functions that exist in Windows that we can tell VBA, "Hey, go use this thing that's out in Windows." In this thing called user32 and kernel32. Those are Windows libraries.
All right? Last uh get last input info asks Windows when the last keyboard or mouse activity occurred.
And get tick count returns the number of milliseconds that have elapsed since Windows started.
And then we have our get idle seconds function. Let me see if I can scroll down and get this whole thing. Uh you know what? If I get rid of some of the blank lines, I can get the whole thing on the screen. Hang on.
Okay there, I condensed it for you.
All right, so inside the get idle seconds function, we create a variable based on that last input info structure, right? This guy here.
We tell Windows how large the structure is, this thing here, right?
And then call GetLastInputInfo.
And if the call succeeds, Windows fills in the timestamp of the last user input.
Then we call GetTickCount to get the current system tick count. By subtracting the last input time from the current time, we get the number of milliseconds the computer has been idle.
Finally, we divide that by 1,000 to convert milliseconds into seconds, and then we return the result.
If the API call fails for some reason, the function returns -1, so you know something went wrong, and you can check for that if you want to.
All right, so that's it. And again, you don't need to understand all that to use this guy, right? To use this GetIdleSeconds. So now, save this, we're going to close it, and we're going to go test it. I'm going to go in my main menu. We got my status box here, right?
So we're just going to set up a little timer event in the main menu.
All right, let's go down here. I'm going to set the timer interval to 1,000, so it's a 1-second timer. Normally, we don't do this, right? We don't want every second cuz it's going to steal focus every second, but just for testing purposes, all right?
I'm going to go in here.
And I'm just going to say status and then idle {colon} and GetIdleSeconds.
And sec like that. So it'll just every second, it's going to call GetIdleSeconds, it's going to go ask Windows, "Hey, how long have you been idle for?" and just status it for me.
All right, once every second that'll run. All right, save it.
Debug compile. Hopefully, everything compiles. Okay, good, we're good. All right, save it, close it, and then let's open it back up.
And there you go. You can see it's been idle zero, so okay, so now it's counting up cuz I have my hands off. I haven't done anything.
All right? If I go touch my mouse, watch what happens.
Oh, look at that. It reset back to zero again. See? It knows whether or not I'm actually doing something. I'm just going to hit the shift key on the keyboard.
Look at that. Shift reset it to zero.
I'm going to go do something else. Let me open up notepad.
All right, I got notepad open. Totally separate application just sitting over here. I'm just going to I'm going to wait now. Let it go idle. Okay. So, Access doesn't know I'm doing anything.
I haven't touched anything. Now, I'm just going to start typing in notepad.
And look at that. See? Went back to zero. So, my Access database now knows when I'm doing anything anywhere else in Windows.
Isn't that pretty cool?
So, this is a great tool. I would still recommend using the techniques from parts one through three.
Um continue tracking activity inside your Access database and reset your timer on the form whenever the user does something in your application. That's going to prevent your hidden timer form from constantly stealing focus, right? Especially if you're doing stuff in the VBA editor.
You don't want that to happen.
Um then as your final check before logging out the user, you could you could use the get idle seconds.
Right? That Make that like the last straw. Like, are you really here? Are you doing something else? You know, are you are you surfing what Do they Do they still say surfing the web? Is that still a thing? I know that this came up in the forums a little while ago.
I thought that went the way of the information superhighway, right?
Somewhere around 2003.
Um but this way at least if Windows says the user hasn't touched the keyboard or mouse in a long time, you know that they truly stepped away from the computer then.
So, think of this like your last line of defense. The earlier techniques tell you whether they're still using the database, this technique will tell you whether they're still at the computer at all.
And you can even do other stuff, too. If you detect they're not at the computer, you could log them out of their database and then lock the Windows workstation.
If you guys want to see how to do that, let me know. That's pretty easy to do, too. But, that's a whole separate video.
And this is probably going to be the last I I said part three was going to be the last, but this is This is the last part for now, part four. So, let me know what you thought. Post a comment down below. You going to use this? Do you like it? Do you not like it?
You want to see more?
Um but that's going to do it, folks.
That's going to be your tech help video for today. I hope you learned something.
Live long and prosper, my friends. I'll see you next time.
If you enjoyed this video, hit that thumbs up button right now and give me a like.
Also, be sure to subscribe to my channel, which is completely free, and make sure you click that bell icon and select all to receive notifications whenever I post a new video.
If you're new to Microsoft Access, check out my Access Beginner Level 1 course.
It's over 4 hours long, and it covers all the basics like tables, queries, forms, and reports.
It's a great place to start, and it's also completely free.
Members of my channel get extended cut videos, sample databases, access to my code vault, and full training classes every month. Click the join button for details.
Thanks for watching. I'm Richard Rost with accesslearningzone.com.
Live long and prosper, my friends. I'll see you next time.
Ähnliche Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











