473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

IIf Statement for Null Value

418 256MB
My main report contains 3 separate expense sub reports. For my sub report footers I used (one of the sub report shown here) I have this statement

Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNull([Amount]),0,Sum([Amount]))
My goal is to show a zero on the main report footer for those sub reports that don't have any data. This way the footer of the main report should summarirze the grand total for all 3 expenses regardless of there is data or no data. But instead, I get this "#Error" for those sub reports that don't have data.

What will be the correct formula? Thanks.
Jun 4 '09 #1
14 5374
ChipR
1,287 Expert 1GB
Try this:
Expand|Select|Wrap|Line Numbers
  1. = Nz(SUM([Amount]),0)
Jun 4 '09 #2
MNNovice
418 256MB
ChipR:

Sorry but it's still not working. Let me give a little more details.

A text box called txtAllocationCost is on the sub report

Main Report footer has this to show the total from the sub report:

Expand|Select|Wrap|Line Numbers
  1. AllocationCost.Report.txtAllocation
I added this to txtAllocationCost
Expand|Select|Wrap|Line Numbers
  1. =Nz(SUM([Amount]),0) 
The main report still showing #Error for Allocation Cost Total

What am I doing wrong? Thanks.
Jun 4 '09 #3
ChipR
1,287 Expert 1GB
First, do the sub reports have zero in the footers if there is no data?
Jun 4 '09 #4
MNNovice
418 256MB
First, do the sub reports have zero in the footers if there is no data?
No. If there is no data it just shows the labels without any data.
Jun 4 '09 #5
NeoPa
32,556 Expert Mod 16PB
I think you need :
Expand|Select|Wrap|Line Numbers
  1. =Sum(Nz([Amount],0))
This all depends on [Amount] being a correct reference though.

If not, then you need to provide names of the relevant items. The subreport control would be required as well as how the item is referenced within the report itself (the report used within the subreport control).

Repeat a further two times to handle all three figures or take the concept and progress yourself from there, whichever is better for you.
Jun 4 '09 #6
Denburt
1,356 Expert 1GB
When I want to check if the subreport has data then I usually use the following:

Expand|Select|Wrap|Line Numbers
  1. =IIf (SomeSubReport.Report.HasData,Sum(Nz([Amount],0)),0)
Jun 5 '09 #7
MNNovice
418 256MB
Denburt:

It's working for one control and not for the other two. I must have some name(s) messed up.

1. Ap Expenses
Sub Report control on the main report is called APExpenses
The control containing the total amount on the sub report is called txtApNet and the actual field is called NetAmount

So on the sub form I have this in txtApNet:
Expand|Select|Wrap|Line Numbers
  1. =Nz(Sum([NetAmount]),0)
On the Main Report footer for AP Expenses: I have this on the control
Expand|Select|Wrap|Line Numbers
  1. =IIf(APExpenses.Report.HasData,Sum(Nz([NetAmount],0)),0)
I got this: #Error

2. Payroll Expenses
Sub Report control on the main report is called PayExpenses
The control containing the total pay amount on the sub report is called txtPayAmount and the actual field is called PayAmount

So on the sub form I have this in txtPayAmount:
[code]=Nz(Sum([PayAmount],0))CODE]

On the Main Report footer for Payroll Expenses: I have this on the control
Expand|Select|Wrap|Line Numbers
  1. =IIf(PayExpenses.Report.HasData,Sum(Nz([PayAmount],0)),0)
I got this: #Error

3. Allocation Cost
Sub Report control on the main report is called AllocationCost
The control containing the total pay amount on the sub report is called txtAllocation and the actual field is called Amount

So on the sub form I have this in txtAllocation:
[code]=Nz(Sum([Amount],0))CODE]

On the Main Report footer for Payroll Expenses: I have this on the control
Expand|Select|Wrap|Line Numbers
  1. =IIf(AllocationCost.Report.HasData,Sum(Nz([Amount],0)),0)
This one gives correct result. What's wrong with the other two?

I know you are going to say, check those names...(LOL). I did.

Thought I share this with you.

M
Jun 8 '09 #8
NeoPa
32,556 Expert Mod 16PB
I'll try to answer one at a time (any that I can at least).

1. You need :
Expand|Select|Wrap|Line Numbers
  1. =IIf(APExpenses.Report.HasData,APExpenses.Report.txtAPNet,0)
PS. Nicely explained. Made answering very easy.
Jun 8 '09 #9
NeoPa
32,556 Expert Mod 16PB
2 & 3.

Now I'm starting to get confused. I would never expect that code to work correctly, as I see no reference in [Amount] to the sub report. Maybe I'm missing something fundamental, but let me put in suggestions here for the two others and you can see if they work and decide where to go from there.

2.
Expand|Select|Wrap|Line Numbers
  1. =IIf(PayExpenses.Report.HasData,PayExpenses.Report.txtPayAmount,0)
3.
Expand|Select|Wrap|Line Numbers
  1. =IIf(AllocationCost.Report.HasData,AllocationCost.Report.txtAllocation,0)
Jun 8 '09 #10
NeoPa
32,556 Expert Mod 16PB
One other point to mention, which is worth a try but I haven't tested it, is that YourSubreport.Report.Control can be rewritten as YourSubreport!Control. You could try this instead if you find the others work.
1.
Expand|Select|Wrap|Line Numbers
  1. =IIf(APExpenses!HasData,APExpenses!txtAPNet,0)
2.
Expand|Select|Wrap|Line Numbers
  1. =IIf(PayExpenses!HasData,PayExpenses!txtPayAmount,0)
3.
Expand|Select|Wrap|Line Numbers
  1. =IIf(AllocationCost!HasData,AllocationCost!txtAllocation,0)
Jun 8 '09 #11
MNNovice
418 256MB
NeoPa:

I used formula in posting 9 and 10 and it's working fine. Thank you so much. You made my MONDAY.

Although I copied the alternet formula in my notebook (from Bytes), I don't think I am going to attempt it now. May be when I have some leisure time.

Thanks my friend.

M
Jun 8 '09 #12
NeoPa
32,556 Expert Mod 16PB
I'm very pleased to hear it M.

I think Denburt was trying principally to indicate the reference you need to use to determine whether the subreport had anything to show or not. I don't believe he was suggesting the syntax to reference the total as such. I'm only confused that even one of them worked earlier.

That doesn't really matter though. It works and that's great.
Jun 8 '09 #13
Denburt
1,356 Expert 1GB
Glad it is working M thanks for the clarification Neo, obviously I was in a rush to help answer to the question and didn't look it over as thoroughly as I should have. I have been seriously slammed over here and it doesn't look like it's letting up anytime soon.

Have a good day.
Jun 9 '09 #14
NeoPa
32,556 Expert Mod 16PB
No worries mate. That's perfectly understandable, and your post certainly helped me to get the question into perspective properly. It was very helpful.
Jun 9 '09 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brody | last post by:
Hi. I remember using if statements with null in it. For example, at one point I used this: if (value == null) { value = "something"; } document.write(value)
2
by: mvr | last post by:
Hi all I are using IIS 5.0, Oracle 8.1. I am having problem with the following Insert Statement when used on Production Web server with SSL(https://...., Verisign). This doesn't occur...
6
by: ryan.mclean | last post by:
Hi all, first, let me preface this by saying that I am very new to sql server, coming from oracle. Here is my problem: I would like to have a case statement (similar to decode in oracle) that...
9
by: Vorpal | last post by:
Here is a small sample of data from a table of about 500 rows (Using MSSqlserver 2000) EntryTime Speed Gross Net ------------------ ----- ----- 21:09:13.310 0 0 0 21:09:19.370 9000 ...
9
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
3
by: TD | last post by:
I have an unbound form that adds and updates records to one table. I use an INSERT sql statment to add a new record and a UPDATE statement to update a record. I created a function named C2F to...
2
by: Robert Bravery | last post by:
Hi all, Being new to C# and .net I often don't know how to use things. I have created an app that imports excel data, it works well, with methods to open excel, extract the data and close excel....
2
by: commodityintelligence | last post by:
Hello, I am trying to create an IF Statement that checks if a field has a null value. Table mats by sku is a table with skus and 2 columns of data called Index and Category Index Index is...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
1
by: codedhacker | last post by:
I have a piece of code that uses the db-library with sql server 2000/2005 and runs the following delete statement: DELETE FROM TABLE1 WHERE COL1 IN( 'Some Val1' ) AND COL2 IN( 'Some Val2' )...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.