Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIF Statement in an Expression

Status
Not open for further replies.

sparkey75

Technical User
Nov 9, 2009
4
GB
Is it possible to create an IIF statement in an expression in a field so that I can have the results back for the field depending on the IIF statement results?

For example:

IIF field1 is between "a" and "d" and "g" and "z" then field2 else 0

Many thanks for any assistance, as this would be greatfully received.
 
Since a value can't be between "a" and "d" AND "g" and "z", I'm assuming you meant between "a" and "d" OR "g" and "z". Either of the following should work:
Code:
=IIf((Fields!FIELD1.Value >= "a" AndAlso Fields!FIELD1.Value <= "d") OrElse (Fields!FIELD1.Value >= "g" AndAlso Fields!FIELD1.Value <= "z"), Fields!FIELD2.Value, 0)

=Switch(Fields!FIELD1.Value >= "a" AndAlso Fields!FIELD1.Value <= "d", Fields!FIELD2.Value,
        Fields!FIELD1.Value >= "g" AndAlso Fields!FIELD1.Value <= "z", Fields!FIELD2.Value,
        0 = 0, 0)
 
Many thanks that worked perfectly, you're a star!

It is also possible to add another condition so that I can include the following, for example:

I only want to show the results in the field if rate_no does not equal 9 or 999?

Once again, many thanks.
 
Might be easier to wrap this in a little function in the code window to make use of the SELECT CASE statement...

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top