report with query parameter and no data

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

I have a form that has a list box on it that lists all the reports. There is
a preview button on the form to preview the selected report. When the
preview button is used, that is when the parameter input is requested. It
all works fine so long as there is data to show. If there isn't any data, I
get the no data message then an error message coming from the code behind the
preview button. The code is below.

Private Sub btnReportsListingPreview_Click()
On Error GoTo btnReportsListingPreview_Click_Error

If Not IsNull(Me.lstReports) Then
DoCmd.OpenReport Me.lstReports, acViewPreview
DoCmd.RunCommand acCmdFitToWindow

End If

On Error GoTo 0
Exit Sub

btnReportsListingPreview_Click_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
btnReportsListingPreview_Click of VBA Document Form_frmReportModule"

End Sub

What can I do to prevent this error message from occurring? Is there more
to add to the above?

Thanks... John
 
Hi John,

Just check in the error handler for that particular error number. Note
that you may get several different error numbers depending on what happens
(no data, user cancels parameter box, some other possible action?):

btnReportsListingPreview_Click_Error:

If Err.Number <> 1234 And Err.Number <> 2345 Then
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
btnReportsListingPreview_Click of VBA Document Form_frmReportModule"
End If

End Sub

Clifford Bass
 
Thanks. It worked.
.... John


Clifford Bass said:
Hi John,

Just check in the error handler for that particular error number. Note
that you may get several different error numbers depending on what happens
(no data, user cancels parameter box, some other possible action?):

btnReportsListingPreview_Click_Error:

If Err.Number <> 1234 And Err.Number <> 2345 Then
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure
btnReportsListingPreview_Click of VBA Document Form_frmReportModule"
End If

End Sub

Clifford Bass
 
Back
Top