You may find the Nz function useful in the particular instance you describe.
Help has more information about this, but in general it may go something
like this:
=[FirstField]/Nz([SecondField],1)
If [SecondField] is 0, a 1 is used as the denominator in place of the 0.
That would be in an unbound text box. In a calculated query field it would
be:
NewField: [FirstField]/Nz([SecondField],1)
You could use a message box to advise users that they can't use a 0, but the
question becomes where to put the message. If it is in the After Update
event for txtSecondField (the text box bound to [SecondField]) it will run
only if users update the field. You could use the control's Exit event,
assuming that the users go to that control. You could use the AfterUpdate
event for txtFirstField to set the focus to txtSecondField. If you are
using a command button to perform the calculation, you could use its Click
event. And so forth. In any case, maybe something like:
If IsNull[SecondField] Then
msgbox "Can't be 0"
Cancel = True
Else
Me.FirstField/Me.SecondField
End If
"Charles at Cambridge Food"
Can anyone tell me what I can do to replace the standard error messages
that
occur in my reports? For example when deviding totals by zero the #Num!
error appears and I was hoping to include an IIf statement (or the likes
of)
to replace the message with something more suitable.