Report Error

jose.lopes

New member
Local time
Today, 19:20
Joined
Apr 28, 2006
Messages
9
Hi

i 'm wearing the report nodata event to cancel the report load when i have no data. I´m using the code below, Howhever after display the msgbox it gives a error msg (image).
Some help please

Private Sub Report_NoData(Cancel As Integer)
MsgBox "XXXXXXXXXXXXXXXX", vbInformation + vbOKOnly, "YYYYYYYYYYY"
Cancel = -1
End Sub


Thanks
 

Attachments

  • sem nome1.jpg
    sem nome1.jpg
    16.8 KB · Views: 161
runtime error "2501"
the action 'openreport' was cancelled

i think is a system msg... is there any way to stop it

thanks
 
Is the report opened from a button on a form? If so I would probably use the dlookup function to on the record source of the query to see if it contains records. If it does I would open the report. If it contains no records then I would have message box pop up.
 
yap

i agree... and when i'm working only with vba, recordsets, ans sql instructions...it's easyer.

But this apllication is a School Work and is not suposed that the student know all that. i'm trying to simplify!!!

yes, it's open from a form
 
What are the exact requirements? To use the OnNoDate event?
 
the report works under a query. and when it open it avaliate if there're data, case else he undestand's that the report was cancelled
i think there are not special requirements to use the event

Bv Help

NoData Event
See AlsoApplies ToExampleSpecificsThe NoData event occurs after Microsoft Access formats a report for printing that has no data (the report is bound to an empty recordset), but before the report is printed. You can use this event to cancel printing of a blank report.

Private Sub Report_NoData(Cancel As Integer)
Cancel The setting determines whether to print the report. Setting the Cancel argument to True (–1) prevents the report from printing. You can also use the CancelEvent method of the DoCmd object to cancel printing the report.

Remarks
 
Private Sub Command5_Click()
On Error GoTo Err_Command5_Click
DoCmd.OpenReport , etc
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
If Err = 2501 Then
Resume Exit_Command5_Click
Else
MsgBox Err.Description
End If
Resume Exit_Command5_Click


End Sub
 

Users who are viewing this thread

Back
Top Bottom