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

Divide by Zero on Report (#Num!)

ollyb303
Hi,

I have created a report in my Access db which has two columns - I'll call them Number1 and Number2. I have added a textbox to calculate a percentage from these two numbers

=([Number1]/[Number2]) with the format property set as percentage.

My problem. Sometimes the number in Number2 is a zero, which means the result of the expression is invalid and gives me "#Num!" - I understand why this is happening, but I wondered if there was a way around it.

What I would like to happen is that when it is trying to divide by zero, the #Num! is substituted for a blank space or a zero.

This is purely cosmetic as I would like my report to look neater.

Any help gratefully received.

Thanks,

Olly
Jan 4 '08 #1
9 9072
NeoPa
32,556 Expert Mod 16PB
Try setting the result to :
Expand|Select|Wrap|Line Numbers
  1. =IIf([Number2]=0,[Number1],[Number1]/[Number2])
Jan 4 '08 #2
Perfect! Thanks so much, this works a treat.
Jan 4 '08 #3
NeoPa
32,556 Expert Mod 16PB
No worries Olly. Just pleased it helped :)
Jan 4 '08 #4
missinglinq
3,532 Expert 2GB
Or, for those who find iif() confusing, and it can be, especially if nested 12 times, as some are wont to do:

= [Number1] / Nz([Number2], 1)

Linq ;0)>
Jan 5 '08 #5
NeoPa
32,556 Expert Mod 16PB
Good point Linq (in fact that's how I would tend do it myself). I wasn't sure without checking if Nz() was available as a formula within a control though.
Jan 5 '08 #6
missinglinq
3,532 Expert 2GB
Actually, Ade, if you think about it, if one Access function would work in a Control Source, the other would, but in point of fact both of our codes were lacking! Mine took care of the problem if Number2 was Null, and yours took care of the problem if Number2 = 0, but neither took care of both possibilities! So I modified yours!

=IIf([Number2]= 0 or IsNull([Number2]),[Number1],[Number1]/[Number2])

Linq ;0)>
Jan 5 '08 #7
NeoPa
32,556 Expert Mod 16PB
Actually, Ade, if you think about it, if one Access function would work in a Control Source, the other would,
Actually, Nz() is "special" in this respect. I can't remember the finer details of exactly where I've found this (may even be in Excel rather than Access) but there certainly is somewhere where Nz() is not available but other functions are. Sorry I can't be more specific at this time.
but in point of fact both of our codes were lacking! Mine took care of the problem if Number2 was Null, and yours took care of the problem if Number2 = 0, but neither took care of both possibilities! So I modified yours!

=IIf([Number2]= 0 or IsNull([Number2]),[Number1],[Number1]/[Number2])

Linq ;0)>
This comes back to the original question (which I overlooked in my last response but was better focused on for my first) which was that a 0 can sometimes cause a problem. I think it only needs to handle that situation. It doesn't hurt to have the fuller formula there in case others find the thread though and DO have that requirement too.
Jan 5 '08 #8
missinglinq
3,532 Expert 2GB
Well, of course, you'ved piqued my curiosity now! Turns out that VBScript doesn't support the NZ() function, nor can you use it with SQL Server or Access Projects!

It's like Billy Bob Gate's boys said, "Okay, we've created this handy function, now let's see how many places we can find where we won't let it work!"

Linq ;0)>
Jan 6 '08 #9
NeoPa
32,556 Expert Mod 16PB
Something like that ;)
I think I fell over it in an Excel formula though. I just tried it and it doesn't work in there (A1 = "=Nz(B1)" results in #NAME?). I'm not sure where else though.
Jan 6 '08 #10

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

Similar topics

2
by: Mike Leahy | last post by:
All... I have a query that calculates various using variables from a survey database. As with any survey, there are many instantces of null values. I'm wondering if there is any way to escape...
1
by: franknavec | last post by:
I have created a database in MS Access 2000. I want to compute for percent defective and in the control source I have this expression: =((/)*100). Its OK if I have the numbers greater than zero....
0
by: Gary Carson | last post by:
Can anyone tell why the query below would throw a divide-by-zero error? The only reason I can see for the error happening would be if SUM() came out to be zero, but this never happens with the...
4
by: shuisheng | last post by:
Dear all, Assume I have two big arrays A and B. And I want to element-wise divide A by B. When an element of B is zero, the results are also zero. Such as A = { 2, 4, 0, 6} B = { 1, 0, 0, 2}...
5
by: Neo | last post by:
Hi Friends, I am trying following code int main(void) { try { int i,j,k; i=10; j=0;
8
by: =?Utf-8?B?bWljaGFlbGd3ZWllcg==?= | last post by:
Hello! I was working on some code the other day, and I came across an odd discrepancy between the decimal and the double type. If I attempt to divide a decimal by zero, the framework throws an...
1
by: zufie | last post by:
Help! How do I divide by zero on my form (in a text box). That is, how do I carry out a division problem when the denominator is zero? Thanks!, John
1
by: Ajay Indian | last post by:
printf("Divide by zero=%d",1/0); is giving output 1 while x=0,y=1; printf("Divide by zero=%d",y/x);
1
by: Sharon Brennan | last post by:
I would like to divide my report by our departments and then sites. I've gone into properties for each of my sorts and put in page breaks but nothing happens. Everything just runs together on one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.