If Then Problem

Novice1

Registered User.
Local time
Yesterday, 16:22
Joined
Mar 9, 2004
Messages
385
I cannot seem to get this code to work. I've tried OR instead of AND. Am I using the parentheses incorrectly?

If Me.UBLCombo = "MarriedChildren" And (Me.Primary1Relationship <> "Spouse" And Me.Primary1Relationship <> "Child" And Me.Primary1Relationship <> "Stepchild")

Then

Me.Primary1UB = -1
Me.SpouseLetter = -1

Else

Me.Primary1UB = 0
 
And is correct.
Try putting the entire IF in parenthesis....

If (clause) then
 
I cannot seem to get this code to work

Tell us how you know its not working---error message, unexpected results?

With that said, did you leave off some of the code? I don't see an End If
 
I tried adding the parenthesis to include the whole statement (without the inside parenthesis and with the inside parentheses), no luck
 
Write down in English what you think your If statement is testing for.
 
If UBLCombo equals "MarriedChildren" and Primary1Relationship doesn't equals "Spouse" or "Child" or "Stepchild" Then Primary1UB equals Yes (checkmark)
 
In response to Plog. The code is part of a nested If/Then statement (I didn't include all the If/Then statement). Everything responds as expected except when I combine then statements (Primary1Relationship <>). I get no result (no error) but fields don't update either, which is why I thought the <> statements are written incorrectly.
 
I am not sure if your logic is correct.

The (Me.Primary1Relationship <> "Spouse" And Me.Primary1Relationship <> "Child" And Me.Primary1Relationship <> "Stepchild") will never be true if the Primary1Relationship is ever Spouse or Child or Stepchild. I think what you want is (Me.Primary1Relationship= "Spouse" OR And Me.Primary1Relationship = "Child" OR Me.Primary1Relationship = "Stepchild")
 

Users who are viewing this thread

Back
Top Bottom