# Thread: As If clause (Access 2000)

1. ## As If clause (Access 2000)

I have a rather complicated case of ElseIf and im looking for advice. My working If code is as follows:

If code < 60000 Or code > 90000 Then
FRig = (grossprice - Discount)
ElseIf code > 60000 And code < 90000 Then
FRig = grossprice - grossprice * 0.9
End If

I need to add on the following condition;

If code < 18000 and code < 19000 Then
FRig = (grossprice - Discount)* 0.8

Can i enter this line below the If code < 60000 Or code > 90000 Then line?
I am afraid i may twist the logic of the code

2. ## Re: As If clause (Access 2000)

<hr>if code < 18000 and code < 19000 Then<hr>

Anything that is under 18000 is always under 19000.

Have you written this correctly?

3. ## Re: As If clause (Access 2000)

My advice would be to gradually work up or down the values, taking each case in turn. Slot your new option into this.

You don't need to retest for things you have already tested for.

If code < 60000 Then
FRig = (grossprice - Discount)
ElseIf code < 90000 Then
FRig = grossprice - grossprice * 0.9
else
FRig = (grossprice - Discount)

End If

4. ## Re: As If clause (Access 2000)

You can also use a Select Case statement:

Select Case code
Case Is < 18000
FRig = grossprice - Discount
Case Is < 19000
FRig = (grossprice - Discount) * 0.8
Case Is < 60000
FRig = grossprice - Discount
Case Is < 90000
FRig = grossprice - grossprice * 0.9 ' are you sure this is correct?
Case Else
FRig = grossprice - Discount
End Select

You can easily modify and expand this as needed. Like in John Hutchison's example, work from low to high.

5. ## Re: As If clause (Access 2000)

Thank you to you all for your replies ! As you have asked me whether i am sure,you were right, i made it wrong,i actually meant > 18000 and less then 19000 or between 18000 and 19000.My problem is : If the code is less than 60000 an bigger than 90000 then FRig = (grossprice - Discount), but withing this range
anything between bigger than 18000 and less than 19000 should be (grossprice - Discount)* 0.8
So, on the one hand i have the condition code < 60000 Or code > 90000 and on the other hand withing this range, the condition between 18000 and 19000
How could i avoid eventual conflicts ?

6. ## Re: As If clause (Access 2000)

See the code in my previous reply - it handles all ranges.

7. ## Re: As If clause (Access 2000)

Since i am masking a small mess wih my if conditions, i would like to write the orginal code which works fine:
If code < 60000 Or code > 90000 Then
FRig = (grossprice - Discount)
ElseIf code > 60000 And code < 90000 Then
FRig = grossprice - grossprice * 0.9
End If

I need to add on the following condition;
If code > 18000 and code < 19000 Then
FRig = (grossprice - Discount)* 0.8

If code < 60000 Or code > 90000 Then
FRig = (grossprice - Discount)
ElseIf code > 60000 And code < 90000 Then
FRig = grossprice - grossprice * 0.9
End If

I need to add on the following condition;

If code > 18000 and code < 19000 Then
FRig = (grossprice - Discount)* 0.8

8. ## Re: As If clause (Access 2000)

If code > 18000 and code < 19000 Then
FRig = (grossprice - Discount)* 0.8
ElseIf code < 60000 Or code > 90000 Then
FRig = (grossprice - Discount)
ElseIf code > 60000 And code < 90000 Then
FRig = grossprice - grossprice * 0.9
End If

9. ## Re: As If clause (Access 2000)

Thak you very much ! It works so fine !

10. ## Re: As If clause (Access 2000)

This code does not work correctly in all cases, as it does not consider the cases where code = 6000 or code = 9000.
I don't know which case they should fall into. If it is the last then change it to:

If code > 18000 and code < 19000 Then
FRig = (grossprice - Discount)* 0.8
ElseIf code < 60000 Or code > 90000 Then
FRig = (grossprice - Discount)
Else
FRig = grossprice - grossprice * 0.9
End If

This removes a superfluous test, and so it makes it a bit more understandable. By making it even more convoluted than it was, you make it even harder to add another condition later, if the need arises.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•