IIf function

G

Glenn

Hi all,

I get no syntax error on this, but I have one row in a field that divides by
zero and in order not to get a #ERROR in the field, I need to use the
following line

IIf([Number1]/[Number2]<>0,[Number1]/[Number2],0)

Although the above line has no syntax errors, I am still left with #ERROR

I need #ERROR to be 0.
glenn
 
J

Jim Aksel

Your test will blow up if Number2=0 and you will never get to the remainder
of the statement. Try it this way:
IIf([Number2]<>0,[Number1]/[Number2],0)

or

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

--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com
 
G

Glenn

Hi Jim,

Sure ... That makes much more sense and it fixes my problem.

You get an A+
glenn


Jim Aksel said:
Your test will blow up if Number2=0 and you will never get to the remainder
of the statement. Try it this way:
IIf([Number2]<>0,[Number1]/[Number2],0)

or

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

--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com



Glenn said:
Hi all,

I get no syntax error on this, but I have one row in a field that divides by
zero and in order not to get a #ERROR in the field, I need to use the
following line

IIf([Number1]/[Number2]<>0,[Number1]/[Number2],0)

Although the above line has no syntax errors, I am still left with #ERROR

I need #ERROR to be 0.
glenn
 
J

Jim Aksel

Thank you for the feedback, I am happy things worked out for you.
---
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com



Glenn said:
Hi Jim,

Sure ... That makes much more sense and it fixes my problem.

You get an A+
glenn


Jim Aksel said:
Your test will blow up if Number2=0 and you will never get to the remainder
of the statement. Try it this way:
IIf([Number2]<>0,[Number1]/[Number2],0)

or

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

--
If this post was helpful, please consider rating it.

Jim Aksel, MVP

Check out my blog for more information:
http://www.msprojectblog.com



Glenn said:
Hi all,

I get no syntax error on this, but I have one row in a field that divides by
zero and in order not to get a #ERROR in the field, I need to use the
following line

IIf([Number1]/[Number2]<>0,[Number1]/[Number2],0)

Although the above line has no syntax errors, I am still left with #ERROR

I need #ERROR to be 0.
glenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top