Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On No Data works but how to get rid of Access message 1

Status
Not open for further replies.

Eprice

Technical User
May 6, 2003
209
US
Hi,
I am using the on no data code:

Private Sub Report_NoData(Cancel As Integer)
MsgBox ("There is no data for the report."), , "Message Alert"
Cancel = True
End Sub

This works fine but after they get my message an access message 'The open report action was cancelled' also pops up. I think they can deal with just one message, so how do I get rid of the access message.
Thanks
Lisa
 
You need to add error handling to the module/sub that calls the OpenReport command. Something like the following:


On Error GoTo errReport

'code
DoCmd.OpenReport "yourreport" '...

exitSub:
Exit Sub

errReport:
If err.Number = 2501 'no data
Else
MsgBox err.Number & vbCrLf & err.Description
End If
Resume ExitSub
End Sub

Duane
MS Access MVP
 
Thanks Duane that worked! Putting code in the open report module works using:

Set PR = CurrentDb().OpenRecordset("tbl PReport")
DoCmd.SetWarnings False
'----If no records in recordset, give message and don't open report"
If PR.RecordCount > 0 Then
DoCmd.OpenReport "rpt AllocateByPlaintiff", acViewPreview
Else
MsgBox "There are no records for this plaintiff"
Exit Sub
End If
End If

If all we need to do is put it in the open report module then why would we ever use the OnNoData event? Lisa
 
The On NoData and the Cancel events/methods are not the same. You might cancel the report even if there is data.

Duane
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top