473,394 Members | 1,845 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,394 software developers and data experts.

Calculated Control (Text Box) in a Report

(Please forgive any misuse of terms in my description as this is my first post.)
I have created a text box (in a report) that is used to find a percentage based on two other controls. The calculation works fine unless there is a null value in both of the other controls. I would like to find a way to return either a 0 or bit of text (such as "N/A") whenever this situation arises. Currently, I receive the #Num! error.

I have seen posts which discuss how to pass a custom error message through a message box, but I would like mine to appear in the text box. Also, I cannot seem to find the error code number for #Num!, as I do not have the Microsoft Help Add-In avialable to me that provides the information, and I have not been able to find it searching the Web (if this error does indeed have a number).

Any assistance would be appreciated. My code appears below:

Expand|Select|Wrap|Line Numbers
  1. =Nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0)/Nz((Nz([Reports]![Main Report]![SubReport2].[Report]![Jan])+Nz([Reports]![Main Report]![SubReport1].[Report]![Jan])),1)
Jan 25 '07 #1
13 2850
MMcCarthy
14,534 Expert Mod 8TB
This error occurs most frequently when you try to divide by 0. Something like the following should work.

Expand|Select|Wrap|Line Numbers
  1. =IIf(Not IsNull([Reports]![Main Report]![SubReport2].[Report]![Jan]),
  2. Nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0) / (([Reports]![Main Report]![SubReport2].[Report]![Jan]) + 
  3. ([Reports]![Main Report]![SubReport1].[Report]![Jan])),0)
  4.  
Jan 25 '07 #2
First, thank you for your help with this. I tried your suggestion, but I now receive an "Enter Parameter Value" request for the IIF statement. I've tried changing the arguments around, but to no avail.

Also, I'm curious as to why the Nz Statements were taken out of the denominator given that SubReport1 could also be null, causing an error. I'm having a little trouble following the logic, but freely admit that I'm no wiz in that department.

Thanks again.

Here's my code as it appears now:

Expand|Select|Wrap|Line Numbers
  1. =Iff(Not IsNull([Reports]![Main Report]![SubReport2].[Report]![Jan]),
  2. Nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0)/
  3. (([Reports]![Main Report]![SubReport2].[Report]![Jan])
  4. +([Reports]![Main Report]![SubReport1].[Report]![Jan])),0)
Jan 26 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
First, thank you for your help with this. I tried your suggestion, but I now receive an "Enter Parameter Value" request for the IIF statement. I've tried changing the arguments around, but to no avail.

Also, I'm curious as to why the Nz Statements were taken out of the denominator given that SubReport1 could also be null, causing an error. I'm having a little trouble following the logic, but freely admit that I'm no wiz in that department.
I've put them back for SubReport1. Not sure why you're adding Jan field from subreport1 but have also included it in the false statement of the IIf.

Try this ...

Expand|Select|Wrap|Line Numbers
  1. =Iff(Not IsNull([Reports]![Main Report]![SubReport2].[Report]![Jan]),
  2. nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0)/
  3. [Reports]![Main Report]![SubReport2].[Report]![Jan]
  4. +nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0),
  5. 0+nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0))
  6.  
Mary
Jan 26 '07 #4
I've put them back for SubReport1. Not sure why you're adding Jan field from subreport1 but have also included it in the false statement of the IIf.

Try this ...

Expand|Select|Wrap|Line Numbers
  1. =Iff(Not IsNull([Reports]![Main Report]![SubReport2].[Report]![Jan]),
  2. nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0)/
  3. [Reports]![Main Report]![SubReport2].[Report]![Jan]
  4. +nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0),
  5. 0+nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0))
  6.  
Mary
Ok, I've tried this and it does give me a 0 result if both controls are null, but gives me incorrect percentages if one or both are not null (basically acts if the denominator does not exist.)

Because you asked why I added the Jan field from subreport 1, I thought it might be useful to break the problem down into the simplest form possible. Therefore, this is what I'm trying to do:

I have two reports, say A and B, which include a count of records that meet a particular criteria (True-for A or False-for B) per month. I am trying to create a text box that calculates %True out of True+False for a given month. Using the Nz function, my original calculation (basically, T/(T+F), worked except for the occasion when there were no True or False records for a particular month.

I hope this makes things a bit clearer. I'm sure that there may even be a simpler way to go about solving this problem that I've missed.

I appreciate your continued assistance.
Jan 26 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Ok, that helps a lot. Try this ...

Expand|Select|Wrap|Line Numbers
  1. =Iff(nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0) + nz([Reports]![Main Report]![SubReport2].[Report]![Jan],0) <> 0,
  2. nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0) / (nz([Reports]![Main Report]![SubReport1].[Report]![Jan], 0) + nz([Reports]![Main Report]![SubReport2].[Report]![Jan],0)),
  3. nz([Reports]![Main Report]![SubReport1].[Report]![Jan],0) /1)
  4.  
Jan 26 '07 #6
Ok, I will try that on Monday (they've sent us home for the weekend) and let you know how it works. I do really appreciate your help.
Jan 26 '07 #7
NeoPa
32,556 Expert Mod 16PB
You may want to try this version :
Expand|Select|Wrap|Line Numbers
  1. =Nz(Me!SubReport2!Jan,0)/
  2.  IIf(Nz(Me!SubReport1!Jan,0)+
  3.  Nz(Me!SubReport2!Jan,0)=0,1,
  4.  Nz(Me!SubReport1!Jan,0)+
  5.  Nz(Me!SubReport2!Jan,0))
Line breaks are for display purposes only and should be removed before testing.
NB. When referring to items within the same report (I'm assuming this is the case here) you can use Me.
Jan 27 '07 #8
Ok, I tried both of the examples above, and found that the following code makes the equation work:

Expand|Select|Wrap|Line Numbers
  1. =Nz([Reports]![Main Report]![Subreport1].[Report]![Jan],0)
  2. /IIf(Nz([Reports]![Main Report]![Subreport2].[Report]![Jan],0)
  3. +Nz([Reports]![Main Report]![Subreport1].[Report]![Jan],0)=0,
  4. Nz([Reports]![Main Report]![Subreport1].[Report]![Jan],1),
  5. Nz([Reports]![Main Report]![Subreport1].[Report]![Jan],0)
  6. +Nz([Reports]![Main Report]![Subreport2].[Report]![Jan],0))
I thank both of you for your assistance with this.
Jan 29 '07 #9
NeoPa
32,556 Expert Mod 16PB
Is the control not on the same report then. Otherwise I can't see why you'd need the references to be so complicated.
This is not a critical issue if you have it working, but it would certainly make it easier for you to work with in future if it is tidied up.
Jan 29 '07 #10
Is the control not on the same report then. Otherwise I can't see why you'd need the references to be so complicated.
This is not a critical issue if you have it working, but it would certainly make it easier for you to work with in future if it is tidied up.
I believe Me! did not work because I have spaces in my subreport titles (although maybe I could have just used _).
Jan 29 '07 #11
NeoPa
32,556 Expert Mod 16PB
I never use spaces in names myself as they invariably add difficulties. However, in this case, I can't see they would be used at all if you use the Me! reference. Where they are used, of course, you can always surround each name with [] characters.
I'm still intrigued that the Me! reference could not be made to work - for my learning and experience as well as for yours.
Jan 29 '07 #12
I never use spaces in names myself as they invariably add difficulties. However, in this case, I can't see they would be used at all if you use the Me! reference. Where they are used, of course, you can always surround each name with [] characters.
I'm still intrigued that the Me! reference could not be made to work - for my learning and experience as well as for yours.
When I use Me!, I receive a request for a parameter value for Me when I run the report. Perhaps Access doesn't like the mix of brackets/non-brackets - but that is just my guess. (I could also be typing something incorrectly, but can't see the tree for the forest as it were.)
Jan 29 '07 #13
NeoPa
32,556 Expert Mod 16PB
Well, I suppose we'll have to leave it there.
I can't understand why it would ask for Me on its own in this case, but it's not important enough to waste any more time on. You have a solution that works. That's the important thing.
Jan 29 '07 #14

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

Similar topics

2
by: Derek Erb | last post by:
I have a field in a report which is filled by a function. This is because I want the values displayed in a particular way. The field is filled with: strVal = Format(ValLow, "$#,###") & " / " &...
3
by: jdph40 | last post by:
I've been given a database and asked to figure out how to sort a report. The report needs to be sorted on a field that is the sum of a field that is calculated in the underlying query. NetSales...
2
by: Paolo | last post by:
Friends, I have a table with a field named Initials which has its record source to another table named Initials. I would like to add on a form named Welcome two controls: A combo box, which...
1
by: shobhit_shanker | last post by:
Here are the relevant "givens" to my problem... Form: frmLaunchRpt - Text Box: txtAsOfDate - Check Box: chkLogEval - Command Button: cmdLaunchRpt Report: rptEvaluation - Text Box:...
1
by: Dave | last post by:
This one's pretty basic, but I really need help. I have two tables, one with customer information and another which looks up prices depending upon size in united inches. It works fine if I...
30
by: Shannan Casteel via AccessMonster.com | last post by:
I have a subform named "sbfrmParts" with a list of parts along with the quantity and price. I have used a text box in the subform's footer and set the control source to "=Sum(*)". I set the...
2
by: Zlatko Matić | last post by:
I have a field and want to have a calculated field in a report that counts it. It had control source set to "=count (). As can be also Null, I would like it to count only values distinct from...
1
by: administrator | last post by:
Hi, I'm having trouble with a calculated text box. "= & & & & & & & & & & & & & & " This produces the correct results, but I want it to create each outcome below the previous...
2
by: Olveres | last post by:
Hi, I have managed to work out how to add new lines into a calculated text box. However in this text box some of the outcome fields are empty however when previewing the report it includes the...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.