Solved

Access IIf statement giveing me the wrong result.

Posted on 2014-12-03
10
181 Views
Last Modified: 2014-12-03
What is wrong with the following IIf statement?  I am getting negative values in the AdjustedInventoryValue field when I want it to be zero.  Sample data below the formula.  Thanks.

IIf(IsNull([InventoryReserve]![UnpostedINVAmount]),[InventoryReserve]![Value_USD],IIf([InventoryReserve]![Value_USD]+[InventoryReserve]![UnpostedINVAmount]<0,0,[InventoryReserve]![Value_USD]+[InventoryReserve]![UnpostedINVAmount]))

Value_USD      UnpostedInvAmount      AdjustedInventoryValue
 100                                                                     100
 50                              -75                                             0
150                               25                                         175
-25                              10                                           0
0
Comment
Question by:tomfarrar
[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
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40478711
The first part of the IIf() returns Value_USD when UnpostedInvAmount is null.  This expression might work better for you:
IIf(Nz([InventoryReserve]![UnpostedINVAmount],0) + Nz([InventoryReserve]![Value_USD], 0) < 0, 0, (Nz([InventoryReserve]![UnpostedINVAmount],0) + Nz([InventoryReserve]![Value_USD], 0))
0
 
LVL 7

Author Comment

by:tomfarrar
ID: 40478731
Maybe that could work.  What does the Nz() function do?  Thanks.
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40478761
Nz is an abbreviation for Null to zero but the Nz() function lets you specify the actual substitution.

Nz(somefield, 934) returns 934 if somefield is null
Nz(somefield, 0) returns 0 if somefield is null
Nz(somefield, "xyz") returns "xyz" if somefield is null
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 7

Author Comment

by:tomfarrar
ID: 40478769
Okay, I am trying that out.  The formula as written did not work because of a matching "()" problem.  It appears to me the "(" after 0,0, does not need to be there.  Do you agree?  Thanks.
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40478778
Correct.
0
 
LVL 7

Author Comment

by:tomfarrar
ID: 40478821
Thanks, Pat, you formula worked perfectly!  I will remember Nz().....
0
 
LVL 7

Author Closing Comment

by:tomfarrar
ID: 40478823
Thanks again....
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40478851
Null happens, man.
And when it does, you use Nz() to deal with it
I will remember Nz().....

I sent my niece a t-shirt with that on the front
On the back was
Nz(SomethingTrivial, "Oh, well")
Nz(SomethingSerious,"Crap!")
Nz(SomethingCatastrophic,"Run! Run for the hills!")

Her IT guys laugh every time she wears it :)
0
 
LVL 36

Expert Comment

by:PatHartman
ID: 40479094
My husband played softball on an intercompany league and each department had their own t-shirts.  Accounting was green with a dollar sign.  Personnel was yellow with happy faces.  IT was blue with a beer stein and the words "work is the curse of the drinking class" printed in hexadecimal.
0
 
LVL 7

Author Comment

by:tomfarrar
ID: 40479170
That's funny stuff....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 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