Experts,
I have a subform that totals lost dollars on projects. There are many cases although where there are no lost dollars on a project. I'm trying to get the null value into a zero so when it is added to the main form I don't get the #Error. My current sum field in the subform footer to toal the field "Actual Cost" where the null occurs is:
=Nz(Sum([Actual Cost]),0)
If there is no records of dollars lost although I still get the sum field blank and not a zero, hence my main form creates the #Error on the main form.
Please help.....
Function AvoidError(n As Variant, varReplaceWith As Variant)
On Error GoTo AvoidError_Error
AvoidError = Nz(n, varReplaceWith)
AvoidError_Exit:
Exit Function
AvoidError_Error:
AvoidError = varReplaceWith
Resume AvoidError_Exit
End Function
Then change your current control to:
=AvoidError(Sum([Actual Cost]),0)
Depending on your version of Access, that may or may not work. If it doesn't work, set the controlsource to:
=Sum([ActualCost])
and hide the control.
Create another text control and set it's controlsource to:
=AvoidError(Forms![<myMain
Latter versions of Access have an optimization built-in that if it sees a domain function (like Sum()), it won't call anything else in the expression (I think it's a bug, but that's another story) and AvoidError just doesn't get called.
Jim.