If Then Statement

Novice1

Registered User.
Local time
Yesterday, 23:59
Joined
Mar 9, 2004
Messages
385
This After Update action doesn't work. Am I permitted to write a compound And statement.

If Me.QMarried = -1 And (Me.Primary1Relationship <> "Spouse" Or Me.Primary1Relationship <> "Parent" Or Me.Primary1Relationship <> "Child") Then
Me.UnusualBefLtr = -1

Else
Me.UnusualBefLtr = 0
End If
 
Yes you are, but OR's and NOTS are a tricky beast:

(Me.Primary1Relationship <> "Spouse" Or Me.Primary1Relationship <> "Parent" Or Me.Primary1Relationship <> "Child")

That will always resolve to true. If your variable equals "Spouse" it doesn't equal "Parent" so it evaluates True. If your variable equals "Parent" then it doesn't equal "Child" so it evaluates True. It will always be true no matter the value of your variable.

You should use ANDs in there, not ORs.
 
Thank you. Now that you've explained it, I see the errors. I need to think this out clearly.
 
Try this instead -- I think this does what you were striving to do. Note I put the Me.QMarried on the outside because I am assuming that if Me.QMarried <> -1 you wanted to do nothing -- if not then you can just remove the inner If and put the whole thing on one line.

Code:
If Me.QMarried = -1 Then
    If Me.Primary1Relationship = "Spouse" Or Me.Primary1Relationship = "Parent" Or Me.Primary1Relationship = "Child" Then
        Me.UnusualBefLtr = 0
    Else
        Me.UnusualBefLtr = -1
    End If
End If
 

Users who are viewing this thread

Back
Top Bottom