avoiding #ERROR in an empty report

  • Thread starter Thread starter Sharon
  • Start date Start date
S

Sharon

Hi,

I have fields that do "Sum" of other fields in the report.

When the report is empty, I get ERROR in the fields with
the sum calculation.
I tried to add this condition:
IIf([payment]="",0,sum([pament]) and it didn't change the
ERROR value of the field.

Any idea?

Thanks in advance,
Sharon
 
The report has a NoData event that fires if the report has no data. Just
cancel this event so the report does not show.
 
Sharon,
I think you need to check out Help on "OnNoData" (Cancel the printing of
a report when it doesn't contain any records).
You're calcs will error because there's no data to report... no nulls, no
zeros, no values.
Using the Report's NoData event...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

hth
Al Camp
 
Hi Al

You might want to update that code.
Since A2000, the "@" character does not work like that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

AlCamp said:
Sharon,
I think you need to check out Help on "OnNoData" (Cancel the printing of
a report when it doesn't contain any records).
You're calcs will error because there's no data to report... no nulls,
no
zeros, no values.
Using the Report's NoData event...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

hth
Al Camp

Sharon said:
Hi,

I have fields that do "Sum" of other fields in the report.

When the report is empty, I get ERROR in the fields with
the sum calculation.
I tried to add this condition:
IIf([payment]="",0,sum([pament]) and it didn't change the
ERROR value of the field.

Any idea?

Thanks in advance,
Sharon
 
OK. I didn't even see those characters. I just cut and pasted from my
Help to make my response clearer.
Thanks,
Al Camp

Allen Browne said:
Hi Al

You might want to update that code.
Since A2000, the "@" character does not work like that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

AlCamp said:
Sharon,
I think you need to check out Help on "OnNoData" (Cancel the printing of
a report when it doesn't contain any records).
You're calcs will error because there's no data to report... no nulls,
no
zeros, no values.
Using the Report's NoData event...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

hth
Al Camp

Sharon said:
Hi,

I have fields that do "Sum" of other fields in the report.

When the report is empty, I get ERROR in the fields with
the sum calculation.
I tried to add this condition:
IIf([payment]="",0,sum([pament]) and it didn't change the
ERROR value of the field.

Any idea?

Thanks in advance,
Sharon
 
Thanks you very much for your help.

I did like you suggested, and indeed the message appears
when I try to open an empty report. However, after this
message, the following message appears:
"Run-time error '2501'
The open report action was canceled"
and the option to Debug or Close.

How can I avoid this message?

Thanks a lot,
Sharon
-----Original Message-----
Sharon,
I think you need to check out Help on "OnNoData" (Cancel the printing of
a report when it doesn't contain any records).
You're calcs will error because there's no data to report... no nulls, no
zeros, no values.
Using the Report's NoData event...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

hth
Al Camp

Hi,

I have fields that do "Sum" of other fields in the report.

When the report is empty, I get ERROR in the fields with
the sum calculation.
I tried to add this condition:
IIf([payment]="",0,sum([pament]) and it didn't change the
ERROR value of the field.

Any idea?

Thanks in advance,
Sharon


.
 
Error 2501 is just Access' way of notifying your code that the report did
not open. Use error handling in the procedure that calls OpenReport, and
just ignore the error:

This kind of thing:

Private Sub cmdPrint_Click()
On Error GoTo Err_Handler

DoCmd.OpenReport "MyReport", acViewPreview

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox Err.Description, "cmdPrint_Click"
End If
Resume Exit_Handler
End Sub


--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Sharon said:
Thanks you very much for your help.

I did like you suggested, and indeed the message appears
when I try to open an empty report. However, after this
message, the following message appears:
"Run-time error '2501'
The open report action was canceled"
and the option to Debug or Close.

How can I avoid this message?

Thanks a lot,
Sharon
-----Original Message-----
Sharon,
I think you need to check out Help on "OnNoData" (Cancel the printing of
a report when it doesn't contain any records).
You're calcs will error because there's no data to report... no nulls, no
zeros, no values.
Using the Report's NoData event...

Private Sub Report_NoData(Cancel As Integer)
MsgBox "The report has no data." _
& "@Printing the report is canceled. " _
& "@Check the source of data for the report to make sure you " _
& "entered the correct criteria (for example, a valid range " _
& "of dates).", vbOKOnly + vbInformation
Cancel = True
End Sub

hth
Al Camp

Hi,

I have fields that do "Sum" of other fields in the report.

When the report is empty, I get ERROR in the fields with
the sum calculation.
I tried to add this condition:
IIf([payment]="",0,sum([pament]) and it didn't change the
ERROR value of the field.

Any idea?
 
Back
Top