Error handling on Access reports

J

JoyofComputing

How do I replace that #error message on a report that results from no data
found in the underlying query. I would like to return either zeroes or "no
data"
 
F

fredg

How do I replace that #error message on a report that results from no data
found in the underlying query. I would like to return either zeroes or "no
data"

Code the report's OnNoData event:

MsgBox "There is no data to report on"
Cancel = True

You'll get a message and the report will not run.

If the report was opened from a command button on a form (a
switchboard for instance), this will result in an error. Trap the
error in the command button event that opened the report:
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName"
Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.number & " " & Err.Description
End If
Resume Exit_This_Sub
 
D

Dave M

You can use the IsError() function to replace this in individual situations,
e.g. in a text box that reports a value from a subreport


=IIf(IsError([MySubreport]![MyControl]),0",[MySubreport].Report![MyControl])
 

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