Disconnect users at 5pm every day [DateDiff question]

J

Jimbo213

Hi -
I am trying to shut down any user who left for the day with the application
still open on their desktop. I want this to run at 5pm every day.

I set a variable "duration" to be the time [in seconds] between when the
user signs in [on switchboard form load] and 5pm or 1700 hours. I then use
the form_timer function to shut down when that duration is reached.

Please help by correcting the DateDiff code below.
I have no idea how to do it and I've checked this discussion group's posts
for about 1 hour already. Thanks.

Private Sub Form_Timer()
Application.Quit acQuitSaveAll
End Sub

Private Sub Form_Load()
' Set the timer interval to be the interval from NOW(log-on) to 5pm
Dim duration As Integer
duration = DateDiff("s", [NOW()], [1700 hours today])
Me.TimerInterval = 1000 * duration
End Sub
 
K

Klatuu

You can do it in one line:

Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
 
K

Klatuu

It depends on your rules. If you want it be be just you, then you can add
code to not set the time if it is you who is logged on.
--
Dave Hargis, Microsoft Access MVP


Jimbo213 said:
So Dave, what happens when I log-in at 5:01 pm and the Me.TimerInterval is
then set to minus 1 minute? How does MS-Access respond? Will it also let
anyone who logs-in at 5:01 remain in the application and, therefore, lock it
from my maintenance work?

I need to be able to be the only login available after 5pm.
Application.CurrentUser = "jeb5" <---- that's me

How to accomplish that?

Thanks for your reply & assistance.
Jimbo213


Klatuu said:
You can do it in one line:

Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
--
Dave Hargis, Microsoft Access MVP


Jimbo213 said:
Hi -
I am trying to shut down any user who left for the day with the application
still open on their desktop. I want this to run at 5pm every day.

I set a variable "duration" to be the time [in seconds] between when the
user signs in [on switchboard form load] and 5pm or 1700 hours. I then use
the form_timer function to shut down when that duration is reached.

Please help by correcting the DateDiff code below.
I have no idea how to do it and I've checked this discussion group's posts
for about 1 hour already. Thanks.

Private Sub Form_Timer()
Application.Quit acQuitSaveAll
End Sub

Private Sub Form_Load()
' Set the timer interval to be the interval from NOW(log-on) to 5pm
Dim duration As Integer
duration = DateDiff("s", [NOW()], [1700 hours today])
Me.TimerInterval = 1000 * duration
End Sub
 
J

Jimbo213

Dave - thanks so very much for taking the time to reply

Two questions:
1) on your prior response, what will happen if Me.TimerInterval is negative
[someone logs in at 5:01pm]? What will access do in that case?

2) on your current response, build code Like this ?

Code on the switchboard form which auto-loads for all logins:

If (Time > 1700 Or Time < 2000) And Application.CurrentUser <> "jeb5" then
MsgBox "Restricted Sign-On between 5-8 pm"
Cancel = True
Else
Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
End If

[yet this code still allows Me.TimerInterval to go negative if
[someone logs-in after 2000 hours / 8 pm won't it ??
[Idea: I guess I could just restrict access from 5pm to midnight !! ]

Please correct any syntax errors in above or provide a better way.

Thanks for your reply & assistance, Dave.
Jimbo213


Klatuu said:
It depends on your rules. If you want it be be just you, then you can add
code to not set the time if it is you who is logged on.
--
Dave Hargis, Microsoft Access MVP


Jimbo213 said:
So Dave, what happens when I log-in at 5:01 pm and the Me.TimerInterval is
then set to minus 1 minute? How does MS-Access respond? Will it also let
anyone who logs-in at 5:01 remain in the application and, therefore, lock it
from my maintenance work?

I need to be able to be the only login available after 5pm.
Application.CurrentUser = "jeb5" <---- that's me

How to accomplish that?

Thanks for your reply & assistance.
Jimbo213


Klatuu said:
You can do it in one line:

Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
--
Dave Hargis, Microsoft Access MVP


:


Hi -
I am trying to shut down any user who left for the day with the application
still open on their desktop. I want this to run at 5pm every day.

I set a variable "duration" to be the time [in seconds] between when the
user signs in [on switchboard form load] and 5pm or 1700 hours. I then use
the form_timer function to shut down when that duration is reached.

Please help by correcting the DateDiff code below.
I have no idea how to do it and I've checked this discussion group's posts
for about 1 hour already. Thanks.

Private Sub Form_Timer()
Application.Quit acQuitSaveAll
End Sub

Private Sub Form_Load()
' Set the timer interval to be the interval from NOW(log-on) to 5pm
Dim duration As Integer
duration = DateDiff("s", [NOW()], [1700 hours today])
Me.TimerInterval = 1000 * duration
End Sub
 
K

Klatuu

The syntax for this line:
If (Time > 1700 Or Time < 2000) And Application.CurrentUser <> "jeb5" then
Would be:
If (Time > TimeSeriay(17,0,0) Or Time < TimeSerial(20,0,0) And
Application.CurrentUser <> "jeb5" then

As to the negative time, you would have to add logic to see if the interval
is a negative number, then add back the time between the current time and
midnight + the time from midnight to 5:00:00 PM.

But, I really think this is the hard way. I would just set the timer
interval to 1 minute. and check to see if it is >= 5:00:00 PM on some date.
If the user logged on between 8:00 and 12:59, then add a day to the time to
check.
--
Dave Hargis, Microsoft Access MVP


Jimbo213 said:
Dave - thanks so very much for taking the time to reply

Two questions:
1) on your prior response, what will happen if Me.TimerInterval is negative
[someone logs in at 5:01pm]? What will access do in that case?

2) on your current response, build code Like this ?

Code on the switchboard form which auto-loads for all logins:

If (Time > 1700 Or Time < 2000) And Application.CurrentUser <> "jeb5" then
MsgBox "Restricted Sign-On between 5-8 pm"
Cancel = True
Else
Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
End If

[yet this code still allows Me.TimerInterval to go negative if
[someone logs-in after 2000 hours / 8 pm won't it ??
[Idea: I guess I could just restrict access from 5pm to midnight !! ]

Please correct any syntax errors in above or provide a better way.

Thanks for your reply & assistance, Dave.
Jimbo213


Klatuu said:
It depends on your rules. If you want it be be just you, then you can add
code to not set the time if it is you who is logged on.
--
Dave Hargis, Microsoft Access MVP


Jimbo213 said:
So Dave, what happens when I log-in at 5:01 pm and the Me.TimerInterval is
then set to minus 1 minute? How does MS-Access respond? Will it also let
anyone who logs-in at 5:01 remain in the application and, therefore, lock it
from my maintenance work?

I need to be able to be the only login available after 5pm.
Application.CurrentUser = "jeb5" <---- that's me

How to accomplish that?

Thanks for your reply & assistance.
Jimbo213


:

You can do it in one line:

Me.TimerInterval = Datediff("s",Time, TimeSerial(17,0,0)) * 1000
--
Dave Hargis, Microsoft Access MVP


:


Hi -
I am trying to shut down any user who left for the day with the application
still open on their desktop. I want this to run at 5pm every day.

I set a variable "duration" to be the time [in seconds] between when the
user signs in [on switchboard form load] and 5pm or 1700 hours. I then use
the form_timer function to shut down when that duration is reached.

Please help by correcting the DateDiff code below.
I have no idea how to do it and I've checked this discussion group's posts
for about 1 hour already. Thanks.

Private Sub Form_Timer()
Application.Quit acQuitSaveAll
End Sub

Private Sub Form_Load()
' Set the timer interval to be the interval from NOW(log-on) to 5pm
Dim duration As Integer
duration = DateDiff("s", [NOW()], [1700 hours today])
Me.TimerInterval = 1000 * duration
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top