Run Code Between Business Hours

AccessNub

Registered User.
Local time
Today, 05:29
Joined
Jul 22, 2006
Messages
71
Hi All,

I've been running around in circles trying to get this to do what I want and it seems to ignore my request, so I figure I must be doing it wrong, so once again, I am asking for help.

What I am trying to do is execute a function M-F every 2 hours between 4am and 6pm. The 2 hour part was easy, I just created a form with a timer, but the other part isn't working so well, here is my latest attempt, can one of you fine gentlemen please fix it for me? TIA

Code:
StrTime = Time()
If Not ((Weekday(Now()) = vbSaturday) Or (Weekday(Now()) = vbSunday)) And (StrTime > "4:00" Or StrTime < "18:00") Then
 
How about

If Weekday(Date()) > 1 And Weekday(Date()) < 7 AND Time()> #4:00# And Time() < #18:00# Then

You might also consider a db that did only your process then quit, fired off in Scheduled Tasks.
 
Ok, I got it now. Figures after I ask, I decided to break each criteria down to see where it was failing...should have done that first. It was failing on checking to see if the time was after 6pm.. also I need to Not both weekdays

Here is the new code (that works, yay)

Code:
If Not Weekday(Now()) = 7 And Not Weekday(Now()) = 1 And (StrTime > TimeSerial(4, 0, 0) And StrTime < TimeSerial(18, 0, 0)) Then
 
BTW. I can't run scheduled tasks, they have been disabled by our IT department, fooey.
 

Users who are viewing this thread

Back
Top Bottom