And/Or Statement

A

Ann

Hi,

I'm a beginner and I'm having a problem with my "and" and "or" statements.
I understand why it's not working just not sure of the syntax to make it work
correctly. This statements will identify High, Medium or Low risks by adding
the tag value. Here is what I have:

If SSN.Value = -1 And ysnName.Value = -1 _
And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then
RiskValue = RiskValue + CInt(SSN.Tag) + CInt(ysnName.Tag)
End If

It works fine until I select "Person" then a High risk is selected and it
shouldn't be. I'm trying to get the following:

SSN.Value and ysnName.Value and Entity
or
SSN.Value and ysnName.Value and Person

I seem to be getting:

SSN.Value and ysnName.Value and Entity
or
Person

I hope I've explained it correctly. Thanks in advance.
 
T

Tom van Stiphout

On Fri, 6 Nov 2009 06:35:01 -0800, Ann <[email protected]>
wrote:

I'm not quite following your explanation, but I think parentheses may
help:

If SSN.Value = -1 And ysnName.Value = -1 _
And (Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person")
Then
RiskValue = RiskValue + CInt(SSN.Tag) + CInt(ysnName.Tag)
End If

-Tom.
Microsoft Access MVP
 
D

Dirk Goldgar

Ann said:
Hi,

I'm a beginner and I'm having a problem with my "and" and "or" statements.
I understand why it's not working just not sure of the syntax to make it
work
correctly. This statements will identify High, Medium or Low risks by
adding
the tag value. Here is what I have:

If SSN.Value = -1 And ysnName.Value = -1 _
And Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person" Then
RiskValue = RiskValue + CInt(SSN.Tag) + CInt(ysnName.Tag)
End If

It works fine until I select "Person" then a High risk is selected and it
shouldn't be. I'm trying to get the following:

SSN.Value and ysnName.Value and Entity
or
SSN.Value and ysnName.Value and Person

I seem to be getting:

SSN.Value and ysnName.Value and Entity
or
Person

I hope I've explained it correctly. Thanks in advance.


The logical "And" operator has higher precedence than the "Or" operator.
Since your If statement consists of a number of comparisons joined by And
and Or without any parentheses to group them, it is understood as if it had
been written:

If ( _
(SSN.Value = -1) _
And _
(ysnName.Value = -1) _
And _
(Recipient_of_PHI = "Entity") _
) _
Or (Recipient_of_PHI = "Person") _
Then

Use parentheses to override the default precedence:

If SSN.Value = -1 _
And ysnName.Value = -1 _
And (Recipient_of_PHI = "Entity" Or Recipient_of_PHI = "Person") _
Then
 
A

Ann

That worked! I had tried the () but must have had them in the wrong spot
because I kept getting a "type mismatch" error.

Thank you so much for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top