No data event in report

G

Guest

I have a command button on a form that I am using to open a report showing
items to be despatched on a job. I have the following code on the click event
Private Sub btnDespatchList_Click()
Dim strWhere As String

strWhere = "qryDespatchList.tblShopJob.JobNo =" & "'" & Me.JobNo & "'"
'open despatch report for current order
DoCmd.OpenReport "rptDespatch", acViewPreview, , strWhere

End Sub
The report worked fine until I added the following to the nodata event on
the report
Private Sub Report_NoData(Cancel As Integer)
'Give message that no items are ordered for this job yet
MsgBox "No items are ordered for this" & vbCr _
& "Job currently", vbInformation
Cancel = True

End Sub
If there is no data present the message box appears and then a debug message
come up saying openreport action was cancelled and then goes to the Private
Sub btnDespatchList_Click() event - anyone tell me how to stop this please -
I have used this before and it worked ok
 
A

Allen Browne

Add error handling to btnDespatchList_Click()
In the error handler, tell it to ignore error 2501

Example:

Private Sub btnDespatchList_Click()
On Error Goto Err_Handler

DoCmd.OpenReport ...

Exit_Hander
Exit Sub

Err_Handler
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Sub
 

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