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
  • Learn & ask questions
Solved

Multiple If criteria in one expression vs Code builder

Posted on 2008-06-18
7
674 Views
Last Modified: 2010-04-21
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
Comment
Question by:dabdowb
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 21817332
if you want two conditions met use { AND }

x:iif([A]>0 AND [B]>0, "xxx", "yyy")
0
 
LVL 75
ID: 21817337
Take a look at the Switch() Function instead of using IIF ...

mx
0
 

Author Comment

by:dabdowb
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 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

by:dabdowb
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

by:dabdowb
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
ID: 21979316
no problem
thank you ..

mx
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question