Solved why this doesn't work Fridays

mloucel

Member
Local time
Today, 00:13
Joined
Aug 5, 2020
Messages
356
I have this little piece of code that for some weird reason today [FRIDAY] it doesn't work
Code:
    Dim ActualTime As Date
    ActualTime = TimeValue(Now())
    If WeekdayName(Weekday(Date)) = "Friday" _
        Or _
        WeekdayName(Weekday(Date)) = "Saturday" _
        And _
        ActualTime > #6:30:00 PM# Then
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNOOPEN"
        Exit Sub
    End If

If I get rid of the "or" then it works perfectly, but I must check for Friday and Saturday to be able to close the database and do backups.

What am I doing wrong?
 
Ever thought to see what values you have?

Code:
? WeekdayName(Weekday(Date))
Saturday

I would surround the OR with ()
 
Ever thought to see what values you have?


? WeekdayName(Weekday(Date))
Saturday
yes I used msgbox WeekdayName(Weekday(Date)) and msgbox ActualTime both came out correct, time is < 6 pm [actual time here in California US, is 11:45 AM]
And no matter what it should work for Friday and Saturday regardless
 
AND binds more in the logical connection than OR. You can emphasize the OR connection by using parentheses.
 
Ever thought to see what values you have?

Code:
? WeekdayName(Weekday(Date))
Saturday

I would surround the OR with ()
I used it as you and @ebs17 suggested, and still does not work, but if I get rid of the OR, then it works.. WEIRD

Code:
    If WeekdayName(Weekday(Date)) = "Friday" _
        Or (WeekdayName(Weekday(Date)) = "Saturday") _
        And _
        ActualTime > #6:30:00 PM# Then
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNOOPEN"
        Exit Sub
    End If
 
AND binds more in the logical connection than OR. You can emphasize the OR connection by using parentheses.
Thanks I tried, still doesn't work, except if I get rid of the OR, then it works..

Code:
    If WeekdayName(Weekday(Date)) = "Friday" _
        Or (WeekdayName(Weekday(Date)) = "Saturday") _
        And _
        ActualTime > #6:30:00 PM# Then
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNOOPEN"
        Exit Sub
    End If
 
yes I used msgbox WeekdayName(Weekday(Date)) and msgbox ActualTime both came out correct, time is < 6 pm [actual time here in California US, is 11:45 AM]
And no matter what it should work for Friday and Saturday regardless
ActualTime > #6:30:00 PM# Then ?????
 
Code:
If (WeekdayName(Weekday(Date)) = "Friday" _
        Or WeekdayName(Weekday(Date)) = "Saturday") _
        And ActualTime > #6:30:00 PM# Then ...
 
ActualTime > #6:30:00 PM# Then ?????
SOLVED....

Code:
    If (WeekdayName(Weekday(Date)) = "Friday" Or (WeekdayName(Weekday(Date)) = "Saturday")) _
        And ActualTime > #6:30:00 PM# Then
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNOOPEN"
        Exit Sub
    End If

Just needed to place the WHOLE OR in parenthesis:
Code:
    If (WeekdayName(Weekday(Date)) = "Friday" Or (WeekdayName(Weekday(Date)) = "Saturday")) _
        And ActualTime > #6:30:00 PM# Then
 
SOLVED....

Code:
    If (WeekdayName(Weekday(Date)) = "Friday" Or (WeekdayName(Weekday(Date)) = "Saturday")) _
        And ActualTime > #6:30:00 PM# Then
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "frmNOOPEN"
        Exit Sub
    End If

Just needed to place the WHOLE OR in parenthesis:
Code:
    If (WeekdayName(Weekday(Date)) = "Friday" Or (WeekdayName(Weekday(Date)) = "Saturday")) _
        And ActualTime > #6:30:00 PM# Then
That is correct. You essentially have: A=1 or B=2 and C=3
Without parentheses this is evaluated as A=1 or (B=2 and C=3) because
"And" (conjunction) is stronger than "Or" (inclusive disjunction). See the precedence rules.
 
That is correct. You essentially have: A=1 or B=2 and C=3
Without parentheses this is evaluated as A=1 or (B=2 and C=3) because
"And" (conjunction) is stronger than "Or" (inclusive disjunction). See the precedence rules.
RIGHT.. parentheses force the compiler to evaluate the OR first then the AND, I use the parenthesis just because but never remember the logic of operations, THANK YOU SO MUCH...
 
had it like that before but I thought naah, it reads better when I use the name instead..
Code:
if (WeekdayName(Weekday(Date)) = "Friday"
To
Code:
if Weekday(Date) = vbFriday
Both clearer and simpler
 
Code:
if (WeekdayName(Weekday(Date)) = "Friday"
To
Code:
if Weekday(Date) = vbFriday
Both clearer and simpler
And you beat me.... LOVE IT!!!!, never thought about it..., Implemented.. Thanks..
 

Users who are viewing this thread

Back
Top Bottom