Solved log off users at certain time (1 Viewer)

ilanray

Member
Local time
Today, 08:25
Joined
Jan 3, 2023
Messages
116
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
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:25
Joined
Feb 28, 2001
Messages
27,186
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.
 

isladogs

MVP / VIP
Local time
Today, 06:25
Joined
Jan 14, 2017
Messages
18,221
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:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:25
Joined
Feb 19, 2002
Messages
43,275
Does anyone have the sample database? The download link from Database Journal no longer works.
 

isladogs

MVP / VIP
Local time
Today, 06:25
Joined
Jan 14, 2017
Messages
18,221
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:

NauticalGent

Ignore List Poster Boy
Local time
Today, 01:25
Joined
Apr 27, 2015
Messages
6,341
Here is an excerpt from Andrew Couch's Access Inside and Out...
 

Attachments

  • Microsoft® Access® 2010 VBA Programming_ Inside Out.pdf
    89.6 KB · Views: 68

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:25
Joined
Feb 19, 2002
Messages
43,275
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

  • Auto-Logout.zip
    723.1 KB · Views: 66

ilanray

Member
Local time
Today, 08:25
Joined
Jan 3, 2023
Messages
116
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
 

ilanray

Member
Local time
Today, 08:25
Joined
Jan 3, 2023
Messages
116
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
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:25
Joined
Feb 28, 2001
Messages
27,186
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:25
Joined
Feb 19, 2002
Messages
43,275
And don't forget, NEVER modify code while a timer is running on ANY form. You WILL be sorry.
 

AHMEDRASHED

Member
Local time
Today, 08:25
Joined
Feb 2, 2020
Messages
50
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:25
Joined
Feb 19, 2002
Messages
43,275
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

Top Bottom