Solved log off users at certain time (1 Viewer)

ilanray

Member
Local time
Today, 21:03
Joined
Jan 3, 2023
Messages
123
Hi
I have few users that login at the same time and from some reason at the next day sometimes I get an error message about database so I thought of force the users to log off after 8 o'clock (the hour is just an example) .
Anyone have an idea how do I do it?

Thanks
 
In general, you need a specific architecture of your app AND a specific environment for this to work.

First, you need a form that is always open. It COULD be a switchboard form or dispatcher type form. It could also be a form that gets launched and immediately makes itself invisible. This form needs a timer that wakes up every so often - every 15 or 30 minutes is slow enough to not overload your system. The timer needs to step through the Forms collect to try to close each open form. IF you have the problem that your users leave active forms open (i.e. bound to some underlying record) you might need to look at the Form_Unload events to assure that if this phantom form tries to shut things down, it can. Whether you have a public semaphore somewhere that says "die now" or some other mechanism becomes a matter of trial and error. However, once all the forms are closed except the hidden one, you can then try an Application.Quit from that form, and ITS Form_Unload routine should allow it to be closed.

The other alternative is that EVERY form has a timer and you have a flag in every form's declaration area that gets reset any time some action occurs within the form to reset that flag. As long as your folks don't have the habit of opening multiple forms, this isn't bad because one or two timers with long intervals is not a burden. Several forms with short intervals can become a burden to your system. There is no guideline that says "x timers with interval of y is too much of a burden." That decision depends on too many factors.

Second, IF your site IT shop is hyper-active, they might impose some site policies to lock idle terminals. It can happen that a locked terminal would thwart this shutdown method, depending on just how active your IT group happens to be.
 
Just pulling rank here. I've used it since 2006 & it works perfectly
Here's my version of the form taken from my Attention Seeking Database (isladogs.co.uk)
Its deliberately 'in your face' so it can't be missed and even includes text to speech as reinforcement

1698075993163.png


The Stop Countdown button is just for demo purposes

@GaP42
Grateful for the link as I'd forgotten where it came from and the name of the author (Danny Lessandrini)
 
Last edited:
Does anyone have the sample database? The download link from Database Journal no longer works.
 
I don't but you could try the Wayback Machine for an archived version.

Or you can find almost identical code as the fifth item in my example database:

In fact, I even attributed the code to Danny Lesandrini in that example
 
Last edited:
I looked on my old computer and found that I had downloaded it years ago. I don't know from where though so I hope it is the same version. The forms look the same. I guess I should go through all my old stuff and consolidate it.
 

Attachments

Thanks, I have a code that log off users on demand which I used in Form_Timer().this is on switchboard
is there a way to compare the current time to lets say 22:00 and if it equal then activate that procedure?
Basically What I need is the update the users table and the timer will be activated

Code:
Private Sub Form_Timer()

    Dim rs As Recordset
    Dim db As Database
    Set db = CurrentDb
    Set rs = db.OpenRecordset("select * from UserAccount where UserName = '" & GetUserLogin & "'")
   If rs![ShutDown] = True Then
        If lTimer1 > 0 Then
            Me.lblCountdown1.Caption = "lTimer1=" & lTimer1
            DoCmd.OpenForm "F_Countdown", acNormal, , , acFormAdd, acWindowNormal
            lTimer1 = lTimer1 - 1000
         Else
           lTimer1 = 5000
        End If
   End If
End Sub
 
Thank you all I solve the problem. at the switchboard i create if condition
Code:
CheckTime = format(now(),"Short time")
if CheckTime = "20:00" then
    docmd.openForm ""
end if
 
If I may suggest it, be careful about using short numbers for timers. Running with timer = 5000 is only 5 seconds. If you set the timer to more like 30000 (every 30 seconds) you cut the overhead of your timer by a factor of 6 and yet have an excellent chance to actually catch the "20:00" time slice just fine. Fast timers are not good for systems.
 
And don't forget, NEVER modify code while a timer is running on ANY form. You WILL be sorry.
 
If I may suggest it, be careful about using short numbers for timers. Running with timer = 5000 is only 5 seconds. If you set the timer to more like 30000 (every 30 seconds) you cut the overhead of your timer by a factor of 6 and yet have an excellent chance to actually catch the "20:00" time slice just fine. Fast timers are not good for systems.

i have Simple Live chat between users as messages pop Running with timer = 1000 is only 1 seconds. now 😞 should be better to changed to 30 seconds or delete it from the system , Thank you for your advice . i appreciate it @The_Doc_Man
1698531973530.png
 
If the timer fires at the wrong time, you will lose code. If you have forms that use timers, you MUST have a way to turn off the timers while you are writing code. Busy now. Will post code later if no one else does
 

Users who are viewing this thread

Back
Top Bottom