report with query parameter and no data

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
 
C

Clifford Bass

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
 
J

JohnE

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
 

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