getting #Error when a Count function finds no records

  • Thread starter Thread starter Paul James
  • Start date Start date
P

Paul James

I've got a calculated field that consists of the expression
"=Count([lastname])" which works fine as long as there are some records in
the underlying record source. However, when there are no records to count,
the field displays the #Error value. I tried using the Null to Zero
function NZ() to eliminate the #Error:

=Count(nz([lastname]))

but that didn't work because I still got the #Error.

I also tried the following expression:

=IIf(Count([lastname])>=1,Count([lastname]),"no records for this
period")

but that still returns #Error when there are no records in the recordset.

Can anyone tell me how I can count the records and return a text string like
"no records" when the recordset is empty, instead of getting the #Error when
there are no records to count?

Thanks in advance.

Paul
 
You need the nz function wrapping the Count function:

=nz(Count([lastname]),0)
 
Timothy - thank you for your response. However, I tried the expression you
suggested:

=nz(Count([lastname]),0)

and it doesn't seem to sork because it still displays the #Error message
when there are no records in the recordset.

Any other thoughts?
 
Back
Top