Checking for 5.30pm

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

How can I check in code (in UK locale) if current time is 5.30 or over ?

Thanks

Regards
 
John said:
Hi

How can I check in code (in UK locale) if current time is 5.30 or over ?

Set a form's TimerInterval to 60000 (milliseconds) which is 1 minute. Use
the following code in the form's Timer event:

Private Sub Form_Timer()
If Timer >= 63000 Then ' 5:30 PM
MsgBox "The time is now past 5:30 PM" vbOKOnly
End If
End Sub
 
Wouldn't that generate a message box every 63 seconds? I'd think it would
be something like this in the Timer event (with the interval set as you
described):

If Time > #5:30:00 PM# Then
MsgBox "The time is now past 5:30 PM"
End If
 
It Will in both cases trigger about once a minute once it gets started ,-)
Arvins typo will probably mean you're long gone anyway

I'd add something like:
Private Sub Form_Timer()
static hasrun as boolean
If Now() > Date() + 63000 And Not hasrun Then ' 5:30 PM
hasrun = true
MsgBox "The time is now past 5:30 PM" vbOKOnly
End If
End Sub

Pieter
 
My point was that it would trigger every five minutes no matter what time it
is. I see your point, though. It all depends on the purpose of the
advisory. If for instance the day's shipment needs to arrive at the loading
dock by 6:00, a notice every five minutes may be appropriate.

"Pieter Wijnen"
 
Note that Arvin said to set the Timer Interval to 1 Minute
63000sec = 60sec*60min*17,5hrs

PS Timer Actually Counts the number of secconds elapsed since midnight & is
thus perfectly valid (my mind was elsewhere).
Either of the Proposed checks will work (Timer probably beeing the faster as
it only involves one function call)

No harm intended

Pieter
 
My mind was elsewhere too. I don't know where I came up with five minutes.
Also, I mistakenly saw the 63000 as somehow related to the 60000, rather
than with the Timer function. In short, I confused the timer event with the
timer function, with a few imaginative twists of my own.

"Pieter Wijnen"
 
My original code was written to quit the application at a predetermined
time. What has to be done for this application is to reset the TinerInterval
if you only want a single message:

Private Sub Form_Timer()
If Timer >= 63000 Then ' 5:30 PM
MsgBox "The time is now past 5:30 PM" vbOKOnly
Me.TimerInterval = 0
End If
End Sub

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com

"Pieter Wijnen"
 
The fact is, that the TimerInterval does need to be reset to avoid running
this once per minute after 5:30 PM. My original code quit the application at
5:30 so I could make sure that no one was in the database.
 
I acknowledge that I was in error, for the reasons stated in another part of
the thread about scrambling the timer function and the timer interval in my
brain, and heading off on an odd tangent from there.
 

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

Back
Top