"division by zero" error message

J

Jeff

When I try to run reports or the associated query I get a
pop-up screen telling me "divison by zero" and it won't
produce the report. Help!
 
G

Guest

It's not logical to divide by Zero - try using the IIF function to test the field and carry out the calculation only if greater than zero
 
A

Arvin Meyer

Jeff said:
When I try to run reports or the associated query I get a
pop-up screen telling me "divison by zero" and it won't
produce the report. Help!

You cannot divide by zero. As a workaround, save the following function in a
modules and wrap it around all your divisions done in queries:

Public Function SafeDiv(Numerator As Variant, Denominator As Variant)
'--------------------------------------------------------------------
' Name: SafeDiv
' Purpose: Division by Zero handler
' Inputs: Numerator As Variant
' Denominator As Variant
' Author: Arvin Meyer
' Date: March 25, 1999
'--------------------------------------------------------------------
On Error GoTo Err_SafeDiv
If Not (IsNumeric(Numerator) And IsNumeric(Denominator)) Then
SafeDiv = Null
ElseIf Denominator = 0 Then
SafeDiv = 0
Else
SafeDiv = Numerator / Denominator
End If

Exit_SafeDiv:
Exit Function

Err_SafeDiv:
Select Case Err

Case 0

Case Else
MsgBox Err.Description
Resume Exit_SafeDiv
End Select

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

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

Similar Threads


Top