Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Division by zero errors

Status
Not open for further replies.

ctrox

Programmer
May 30, 2003
9
US
I have a SQL statement that is dynamically built in VBA through an Access form. I have a calculation that is performed within the SQL statement that takes two fields from a table and divides them by each other. It is very possible that either one or both of the fields in the calculation could be zero or null. How do I return a zero for the result of the calculation if one of the fields is zero, instead of it giving me an error message?

Thanks!
 
iif([denominator]=0, 0, [numerator]/[denominator])

That should do the trick...you don't have to check if the numerator is 0 since that'll return 0 anyway. Hope that helps.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top