Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Multiple If criteria in one expression vs Code builder

Posted on 2008-06-18
Medium Priority
709 Views
Is it possible to write one expression in an Access query where both criteria need to be met, two fields need to be updated and then one common exception if either of the conditions are not met?  For example, see below expression:

X: IIf([Master Table]![Purchasing Price with Markup]>0,[Master Table]![Purchasing Price with Markup]*[Master Table]![System Quantity],IIf([Master Table]![Cost Per Unit]>0,[Master Table]![System Quantity]*[Master Table]![Cost Per Unit],"Neither"))

I want to avoid having to use VBA code for this expression if possible, but understand it may be necessary.

Thanks
0
Question by:dabdowb
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 3

LVL 120

Expert Comment

ID: 21817332
if you want two conditions met use { AND }

x:iif([A]>0 AND [B]>0, "xxx", "yyy")
0

LVL 75

Expert Comment

ID: 21817337
Take a look at the Switch() Function instead of using IIF ...

mx
0

Author Comment

ID: 21817383
I actually found out about the AND feature, BUT the key change here is that there are two executions taking place if both conditions are met, as opposed to one.  So, if both fields are greater than zero, then I have two seperate calculations that need to take place, but then if either of those conditionals are not greater than zero, only one result needs to be given for both.

In the meantime, I will check out this switch function.

Thanks,
Matt
0

LVL 75

Accepted Solution

DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 21817394
From the Help File:

Switch Function

Evaluates a list of expressions and returns a Variant value or an expression associated with the first expression in the list that is True.

Syntax

Switch(expr-1, value-1[, expr-2, value-2 & [, expr-n,value-n]])

The Switch function syntax has these parts:

Part Description
expr Required. Variant expression you want to evaluate.
value Required. Value or expression to be returned if the corresponding expression is True.

Remarks

The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren't properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on.

Switch returns a Null value if:

None of the expressions is True.

The first True expression has a corresponding value that is Null.
Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
0

Author Closing Comment

ID: 31468584
Thanks again for your help.  Sorry for the delay, I was working with a co-worker on this project and waiting for them to do some testing before I could give the thumbs up or down.  Cheers.
0

Author Comment

ID: 21977516
Thanks again for your help. Sorry for the delay, I was working with a co-worker on this project and waiting for them to do some testing before I could give the thumbs up or down. Cheers.
0

LVL 75

Expert Comment

ID: 21979316
no problem
thank you ..

mx
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
###### Suggested Courses
Course of the Month11 days, 23 hours left to enroll