Solved why this doesn't work Fridays (1 Viewer)

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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?
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:19
Joined
Sep 21, 2011
Messages
14,301
Ever thought to see what values you have?

Code:
? WeekdayName(Weekday(Date))
Saturday

I would surround the OR with ()
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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
 

ebs17

Well-known member
Local time
Today, 10:19
Joined
Feb 7, 2020
Messages
1,946
AND binds more in the logical connection than OR. You can emphasize the OR connection by using parentheses.
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:19
Joined
Sep 21, 2011
Messages
14,301
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 ?????
 

ebs17

Well-known member
Local time
Today, 10:19
Joined
Feb 7, 2020
Messages
1,946
Code:
If (WeekdayName(Weekday(Date)) = "Friday" _
        Or WeekdayName(Weekday(Date)) = "Saturday") _
        And ActualTime > #6:30:00 PM# Then ...
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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
 

tvanstiphout

Active member
Local time
Today, 01:19
Joined
Jan 22, 2016
Messages
222
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.
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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...
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:19
Joined
May 21, 2018
Messages
8,529
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
 

mloucel

Member
Local time
Today, 01:19
Joined
Aug 5, 2020
Messages
153
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

Top Bottom