Nested If

G

Guest

I am using Access 2000. I am trying to create a macro to set a value of a
form field (AmtDue) based upon one of five nested conditions:

1) If CodeFieldA = "S" or "M", then AmtDue = 0
Else
2) If CodeFieldB Like "RB*, then AmtDue = 0
Else
3) If RateFieldA > RateFieldB then AmtDue = RateFieldA - RateFieldB
Else
4) If RateFieldA < RateFieldB then AmtDue = RateFieldA
Else
5) If RateFieldA = RateFieldB then AmtDue = RateFieldB.

Each subsequent test is based upon a False condition on the prior condition,
the last condition RateFieldA = RateFieldB is the default.

How do I code this?
 
D

Douglas J. Steele

If CodeFieldA = "S" Or CodeFieldA = "M" Then
AmtDue = 0
ElseIf CodeFieldB Like "RB*" Then
Amt Due = 0
ElseIf RateFieldA > RateFieldB Then
AmtDue = RateFieldA - RateFieldB
ElseIf RateFieldA < RateFieldB Then
AmtDue = RateFieldA
Else
AmtDue = RateFieldB
End If

There's no need to actually check whether RateFieldA = RateFieldB since you
already know RateFieldA isn't greater than RateFieldB and that it isn't less
than RateFieldB.
 

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