'And' and 'Or' in the same if statement

cmray58

Registered User.
Local time
Today, 11:13
Joined
Mar 24, 2014
Messages
70
Hello,

I'm trying to accomplish the following in VBA:

If condition1 = X AND (condition2 = Y OR condition3 = Y) THEN ..........

Ex:
If [Eligible_PROSPollock] = "Eligible" And [Interested_PROSPollock] <> "Yes" Or "No" Then

However, I keep getting a type mismatch error
 
If [Eligible_PROSPollock] = "Eligible" And ([Interested_PROSPollock] <> "Yes" Or [Interested_PROSPollock] <> "No") Then

But even that does not make sense.

What type of field is Interested_PROSPollock?

What value will [Interested_PROSPollock] have if not Yes or No?
 
Hi. You need to follow the same structure. For example, you knew it has to be something like this:
Code:
If condition1=x AND (condition2=y OR condition3=z) Then
But it looks like you forgot condition3 when you did this:
Code:
If [Eligible_PROSPollock] = "Eligible" And ([Interested_PROSPollock] <> "Yes" Or [condition3]="No") Then
 
I'm thinking that the parentheses will make a world of difference here. Did you perhaps mean....

Code:
IF ( ( [Elibigle_PROSPollock] = "Eligible" ) AND ( [Interested_PROSPollock] <> "Yes" ) ) OR ( [Interested_PROSPollock] <> "No" ) THEN ...

The other way with the parentheses would form a tautology if the expression could never be anything else other than "YES" or "NO" - and a tautology can be completely eliminated from the statement.
 
Hmm. I took tautology in school many times, sequentially, and in order one after the other.
 
Why not using nesting IFs?
Code:
If condition1 = X then
    IF condition2 = Y OR condition3 = Y THEN 
          ..........
    End IF
End IF
 
If my suspicions are correct, the problem would be that the OP has to rearrange the order of testing for a nested IF to work - though it WOULD have a shot if rearranged correctly.
 
Even if you take out the lack of the third condition syntax error , the type mis-match error is probably the use of "Yes" when it's maybe a Boolean field and should be True or False (or 0 and -1, or Yes or No without the quotes) ?
 

Users who are viewing this thread

Back
Top Bottom