suppress or cancel error message

A

Alylia

I have a form from which I open all the reports of my datebase, but on my
reports, I have activated the On No Data event. This event works well
whenever I click on any report's command button to open reports which gives
me the "no data found" message if there are no records to be retrieved based
on the criteria. After I have clicked on OK, I get the msg "The OpenReport
action was canceled".

I need assistance on how this can be canceled as well.
 
A

Alylia

Thanks for your support.

Please find below how I have inputted syntax. I am have complie error and
syntax error with "strReport = <PZB06 Periodic Requisition Report>" being
highlighted. Can you please let me know what is that I am doing that is not
correct.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records to report", vbExclamation, "No Records"
Cancel = True

Const conNODATA = 2501
Dim strReport As String

strReport = <PZB06 Periodic Requisition Report>

On Error Resume Next
DoCmd.OpenReport strReport
Select Case Err.Number
Case 0
' no error so do nothing
Case conNODATA
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select

End Sub
 
A

Alylia

Thanks again for your continued support.

I have made the suggested changes but I am still getting the canceled report
message, infact it is as though nothing has been attempted. Please also note
that I use a command button to open each report and not a combo box. You can
review the syntax below and let me know where I am going wrong.

Private Sub cmdReq6_Click()
On Error GoTo Err_cmdReq6_Click

Dim stDocName As String

stDocName = "PZB06 Periodic Requisition Report"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdReq6_Click:
Exit Sub

Err_cmdReq6_Click:
MsgBox Err.Description
Resume Exit_cmdReq6_Click

Const conNODATA = 2501
Dim strReport As String

strReport = "PZB06 Periodic Requisition Report"

On Error Resume Next
DoCmd.OpenReport strReport
Select Case Err.Number
Case 0
' no error so do nothing
Case conNODATA
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select

End Sub
 
K

Ken Sheridan

The use of the < and > characters in my example was simply a convention to
indicate that that was where you put something which evaluated to the name of
the report. This could be a literal string, a reference to a control on the
form (a combo box of report names for instance) etc.

I take it that in your case PZB06 Periodic Requisition Report is the actual
name of the report, so o open that report you'd use a literal string,
delimited with quotes:

strReport = "PZB06 Periodic Requisition Report"

More importantly, however, the code does not go in the report's NoData event
procedure, but in the event procedure where the code which opens the report
is, presumably the Click event procedure of a button on a form.

You said in your original post that the form opens all reports, so you
probably don't want a literal string as the report name in fact. If for
instance you have a combo box, cboReports, on the form which lists al reports
by name then you'd refer to that:

strReport = Me.cboReports

Ken Sheridan
Stafford, England
 
K

Ken Sheridan

Handle the error in the code:

Const conNODATA = 2501
Dim strReport As String

strReport = <get report name from somewhere>

On Error Resume next
DoCmd.OpenReport strReport
Select Case Err.Number
Case 0
' no error so do nothing
Case conNODATA
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select

Ken Sheridan
Stafford, England
 
F

fredg

I have a form from which I open all the reports of my datebase, but on my
reports, I have activated the On No Data event. This event works well
whenever I click on any report's command button to open reports which gives
me the "no data found" message if there are no records to be retrieved based
on the criteria. After I have clicked on OK, I get the msg "The OpenReport
action was canceled".

I need assistance on how this can be canceled as well.

Trap the Error 2501 in the Click event of the button that
started the whole process:

On Error Goto Err_Handler
DoCmd.OpenForm "ReportName", acViewPreview
Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
End Sub
 
K

Ken Sheridan

You are mixing two types of error handling here, inline error handling from
my code, and branching to an error handler, as used when a wizard creates a
procedure. You should use one or the other, e.g. using inline error handling:

Private Sub cmdReq6_Click()

Const conNODATA = 2501
Dim strReport As String

strReport = "PZB06 Periodic Requisition Report"

On Error Resume Next
DoCmd.OpenReport strReport, acPreview
Select Case Err.Number
Case 0
' no error so do nothing
Case conNODATA
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select

End Sub

Or by branching to an error handler:

Private Sub cmdReq6_Click()

On Error GoTo Err_cmdReq6_Click

Const conNODATA = 2501
Dim stDocName As String

stDocName = "PZB06 Periodic Requisition Report"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdReq6_Click:
Exit Sub

Err_cmdReq6_Click:
Select Case Err.Number
Case conNODATA
' anticipated error so do nothing
Case Else
' unknown error so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select
Resume Exit_cmdReq6_Click

End Sub

Ken Sheridan
Stafford, England
 

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