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

Calculation is giving me an error

I have a calculated field on a form that has this formula:

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),[Field2]/[Field3])

The problem is when the if statement is false, it's partly because Field2 is
zero, so when it tries to devide 0/Field3 it gives me an error (#Num!). I
would like to get the result "null" and leave the field blank or return "N/A".
ALSO, I have 5 groups that I use this same formula on and there is another
calculated field that gives me an average of all 5 groups that looks like
this:

=([group1]+[group2]+[group3]+[group4]+[group5])/5

Of course, when I get the #Num! error above it returns a #Error in this
calculated field.

How can I fix this problem? Thanks in advance, you guys are all awesome.
You've helped me so much just by reading other peoples' questions. Thanks a
million!!

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 24 '07 #1
6 1735
"bhrosey via AccessMonster.com" <u33878@uwewrote in message
news:72a7eee3d4fc1@uwe...
>I have a calculated field on a form that has this formula:

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),[Field2]/[Field3])

The problem is when the if statement is false, it's partly because Field2
is
zero, so when it tries to devide 0/Field3 it gives me an error (#Num!). I
would like to get the result "null" and leave the field blank or return
"N/A".
It looks like you need an extra clause in your IIf (untested):

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),IIf([Field2]=0,Null,[Field2]/[Field3]))

Keith.
www.keithwilby.com

May 24 '07 #2
Keith, Thank you! That was close, but you pointed me in the right direction
and I was able to fix that part of it by using this formula:

=IIf([Field1]=[field3],IIf([Field2]=0,null,[Field2]/([Field3]-[Field1])),
[Field2]/[Field3])
because the way you suggested, there could still be a valid value in [field4]
](which doesn't actually figure into the calculation, itself) and by adding
JUST your second IIf statement, it still ignored [field4). The only way I
want to return null is if [field2] AND [field4] are both ZERO and I can tell
that by [field1] and [field3] being equal without having to figure [field4]
into the equation. NOW, that works, but how do I get my other formula to
ignore the null value that I just created?

Keith Wilby wrote:
>>I have a calculated field on a form that has this formula:
[quoted text clipped - 5 lines]
>would like to get the result "null" and leave the field blank or return
"N/A".

It looks like you need an extra clause in your IIf (untested):

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),IIf([Field2]=0,Null,[Field2]/[Field3]))

Keith.
www.keithwilby.com
--
Message posted via http://www.accessmonster.com

May 24 '07 #3
Sorry, I guess I should have included [field4] in my original question. I
didn't think it would figure into things, but I guess it did.

bhrosey wrote:
>Keith, Thank you! That was close, but you pointed me in the right direction
and I was able to fix that part of it by using this formula:

=IIf([Field1]=[field3],IIf([Field2]=0,null,[Field2]/([Field3]-[Field1])),
[Field2]/[Field3])
because the way you suggested, there could still be a valid value in [field4]
](which doesn't actually figure into the calculation, itself) and by adding
JUST your second IIf statement, it still ignored [field4). The only way I
want to return null is if [field2] AND [field4] are both ZERO and I can tell
that by [field1] and [field3] being equal without having to figure [field4]
into the equation. NOW, that works, but how do I get my other formula to
ignore the null value that I just created?
>>>I have a calculated field on a form that has this formula:
[quoted text clipped - 8 lines]
>>Keith.
www.keithwilby.com
--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200705/1

May 24 '07 #4
bhrosey wrote:
>Sorry, I guess I should have included [field4] in my original question. I
didn't think it would figure into things, but I guess it did.
>>Keith, Thank you! That was close, but you pointed me in the right direction
and I was able to fix that part of it by using this formula:
[quoted text clipped - 14 lines]
>>>Keith.
www.keithwilby.com
Actually, this didn't work either, but I did manage to get it fixed with a
much simpler formula.

=IIf([field3]=[field1],Null,[field2]/([field1]-[field3]))

--
Message posted via http://www.accessmonster.com

May 24 '07 #5
bhrosey via AccessMonster.com wrote:
I have a calculated field on a form that has this formula:

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),[Field2]/[Field3])

The problem is when the if statement is false, it's partly because Field2 is
zero, so when it tries to devide 0/Field3 it gives me an error (#Num!).
Then your field3 is 0. You need to deal with that.
I
would like to get the result "null" and leave the field blank or return "N/A".
iif(field1 = 0, "N/A", <do stuff>)


--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
May 25 '07 #6
I think there is an ERROR in the commas and practices...

Hany
www.access-forum.com

Tim Marshall :
bhrosey via AccessMonster.com wrote:
I have a calculated field on a form that has this formula:

=IIf([Field1]<>0,[Field2]/([Field3]-[Field1]),[Field2]/[Field3])

The problem is when the if statement is false, it's partly because Field2 is
zero, so when it tries to devide 0/Field3 it gives me an error (#Num!).

Then your field3 is 0. You need to deal with that.
I
would like to get the result "null" and leave the field blank or return "N/A".

iif(field1 = 0, "N/A", <do stuff>)


--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
May 26 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jlf | last post by:
Need serious help with a calculation. The fields are based on a query that has linked many different tables. The calculation I currently have is: =sum()/((+)*(Piecesnum])) It is giving a...
4
by: vg-mail | last post by:
Hello all, I have identical design for form and report but I am getting calculation error on form and everything is OK on report. The form and report are build up on SQL statement. The...
6
by: David | last post by:
Hi, I have the following calculation I am trying to work out ..... Not sure how ? Variable 1 = minstock Variable 2 = oDict(oKey) I need to test if my variable 'minstock' <= 40% of...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
1
by: cnixuser | last post by:
I am posting this on behalf of a friend of mine who is trying to write a simple program that calcuates pi. He is trying to get as many decimal points as possible down in the calculation ;however, no...
1
by: sujitbhattacharya | last post by:
Dear Community Sir I have two fields in a table and both of them are of number Data Type (as per ACCESS format). The following is the code Through which I'm trying to enter a calculated data in...
2
by: hcso | last post by:
We have a form that has unbound calculation fields that we want to link to a table. Both the form and the table have already been created. How should I start my Visual Basics entry? I keep trying...
5
by: =?Utf-8?B?ZG9uZGlnaXRlY2g=?= | last post by:
I having problems getting this function to return the correct value. Basically I have a curveDataCalc method that loops as it should, but just doesn't seem to be working right. I've stepped through...
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:
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: 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...

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.