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.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Sharon" <(E-Mail Removed)> wrote in message
news:108501c4ae0c$347526f0$(E-Mail Removed)...
> 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
>>
>>"Sharon" <(E-Mail Removed)> wrote in
> message
>>news:24df01c4ad53$417d5480$(E-Mail Removed)...
>>> 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?