And/Or Statement

  • Thread starter Thread starter Ann
  • Start date Start date
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.
 
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
 
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
 
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.
 
Back
Top