Link to home
Start Free TrialLog in
Avatar of dabdowb
dabdowb

asked on

Multiple If criteria in one expression vs Code builder

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
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

if you want two conditions met use { AND }

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

mx
Avatar of dabdowb
dabdowb

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dabdowb

ASKER

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.
Avatar of dabdowb

ASKER

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.