getting #Error when a Count function finds no records

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
 
T

Timothy C. Doherty

You need the nz function wrapping the Count function:

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

Paul James

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?
 
P

Paul James

Duane - I tried your suggestion and it works.

Thanks for your help (again).

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top