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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning zero when null 2

Status
Not open for further replies.

dixxy

Technical User
Mar 4, 2003
220
CA
Hello,

I am having a hard time understanding something. I have looked and read a hole bunch of threads on "null", "nz", and "IIF". I am just not getting it.

I have areport that is based on a query, this query will return nothing sometimes, in other words it will have no records at all. One of the fields on the report is a total, this is based on the total feild in the query.

This is what I am trying in terms of code. I put this in the control source of my total field:

=IIf(IsNull([total]),0,[total])

This give me #error, were I would like to have 0

This gives me the same error:

=nz([total],0)

Could anyone clear away the smoke here for me?
 
Access won't let you use functions like Nz on bound controls. Try adding an unbound text box (say, txtTotal), and set as its control source your last attempt from above:
Code:
=nz([total],0)


Hoc nomen meum verum non est.
 
Thanks Cosmo

I was thinking about that after I posted the question...

Found a way...thanks again.

 
If there are no records in the report, then almost any expression you use in a header or footer that references a field in the record source will result in error.

You could use
=IIf([HasData],[YourExpression],0)

Duane
MS Access MVP
 
Thanks Duance, but again this has long as the text feild is unbound...Right?
 
The text field is bound to the expression. The control source of the text box is:
=IIf([HasData],[YourExpression],0)
YourExpression could be [Total] or Sum([Total]) or whatever.

Another gotcha is when the name of the text box is the same as one of the field names.

Duane
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top