Solved Need help with IF AND OR function (1 Viewer)

travel4u

New member
Local time
Today, 02:15
Joined
Nov 12, 2017
Messages
15
I have following IF function in Macro (Field3 is text field):
IF [Field01]=1 And [Field2]=0 And [Field3]="12"
Question: [Field3] has 3 valid values: "12" or "1" or "2"
I have tried this in function, but did'n work correctly:
IF [Field01]=1 And [Field2]=0 And [Field3]="12" Or [Field3]="1" Or [Field3]="2"
 
Last edited:

Gasman

Enthusiastic Amateur
Local time
Today, 00:15
Joined
Sep 21, 2011
Messages
14,265
Try
Code:
IF [Field01]=1 And [Field2]=0 And ([Field3]="12" Or [Field3]="1" Or [Field3]="2")
 

travel4u

New member
Local time
Today, 02:15
Joined
Nov 12, 2017
Messages
15
BUMMER! :) That came to my mind earlier, but didn't try... IT WORKED PERFECTLY! Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:15
Joined
Feb 19, 2002
Messages
43,257
Logical operators have an order of precedence just as arithmetic operators do. Therefore, when you create a compound condition that uses more than one operator, you should use parentheses to ensure that the condition gets evaluated as you intended.

As written, your expression was being evaluated this way:
Code:
IF (  [Field01]=1 And [Field2]=0 And [Field3]="12" )     Or [Field3]="1"       Or [Field3]="2"
 

Users who are viewing this thread

Top Bottom