View Full Version : Null Calculation


Carol
03-12-2000, 03:58 AM
I have a subform which has a listing for additional costs if required. The user inputs the detail and the amount. This is a continuous form, based upon a ConcernID. I have a total in the form footer which gives an overall additional cost total. This total is then transferred to the main form. The problem is these additional fields are not always used. If there are not additional costs, there is not a total field that can be used for the main form and hence the overall cost total (calculated field) of the main form is not showing a total . I would like the total on the subform to state 0 if no records. My control source in my subform is as follows:
=Sum(NZ([Amount],0))
My conrol source in my main form for the total is as follows:
=IIf(IsNull([ConcernID]),0,DSum("[Amount]","ConcernOtherCosts","[ConcernID]=" & [ConcernID]))
My control source in my main form for the overall ConcernID total is as follows:
=NZ([Labour]+NZ([Travel])+NZ([Other])+NZ([Trucking])+NZ([Costs])+NZ([Parts]))

What am I missing.

Thanks.

Afterglow
03-12-2000, 08:35 AM
When using the Null Zero command as you have. You must us a Capital “N” and a lowercase “z”. So it would look like Nz. =Nz([Labour]+Nz([Travel])+Nz([Other])+Nz([Trucking])+Nz([Costs])+Nz([Parts]))

Pat Hartman
03-12-2000, 07:07 PM
The Nz() function works slightly differently in SQL from how it works in code. The CORRECT and COMPLETE format for the command is Nz(yourfield,valueToReturnWhenYourFieldIsNull), therefore, change your code to:
=NZ([Labour,0]+ ...etc.

In SQL where you probably got your example, the default value to return is 0. There is no default when the function is used in code.