# Error on Report

  • Thread starter Thread starter Somecallmejosh
  • Start date Start date
S

Somecallmejosh

Hello,

I have a query set up that feeds a report with several
fields... I have the query set up so that it pulls
records within a certain date range. One other parameter
is the "department" from which the information is
pulled. In a nutshell, when accessing the query/report
one is asked for the date range, and the department, then
the appropriate info is pulled in...

Situation... If there are no records for that department
in that particular date range, the report shows up
with "#Error" in the associated fields. I understand why
this is happening, I would rather it just show zeros
instead. I've tried IIf statements that state the
following:

=IIf([department] Is Null, "0", Count[Department])

However, if there is nothing at all that is pulled into
the query, then I've got no information to work with.
Does any one have any suggestions on ways I can approach
this, so that a report is generated that states there is
no information for the date range requested. I've even
tried adding something to this effect to the header...

=IIf([department] Is Null, "There are no records for the
date range requested", "")

Which also doesn't seem to work.

Sincerely,
Josh
 
Josh,

Have a lokk at the NZ function. Something like nz
([department],0) will return a zero (or whatever you put
after the comma) if department is null.

HTH

Terry
 
If the report has no data at all, then Department is not a null value: it
doesn't exist. That's the reason that referring to it produces an error.

If there is no data, then the report's NoData event fires. You can cancel
the event and pop up a MsgBox so the user gets a message and never sees the
report. (If you used code to OpenReport, you need to trap error 2501, which
is Access's message back to your code that the report did not open.)

Another approach might be to use IsError()
 
Back
Top