Hi Nona,
You have put the code that should go in the report's NoData event procedure
into the double-click event procedure for the command button currently named
"Command4". I have a couple of suggestions:
1.) Rename this command button to give it a more meaningful name. This way,
when you see it's name in VBA code, you will know the function it is intended
to do. Use something like cmdPreviewReport
2.) Use the Click event procedure instead of the double-click event procedure.
3.) Move the On Error statement *above* the line of code that attempts to
open the report. This way, if there is an error opening the report, your
error-handling code will be properly invoked.
Private Sub cmdPreviewReport_Click(Cancel As Integer)
On Error GoTo ProcError
'Open the selected report in the Print Preview window
DoCmd.OpenReport [ReportListControl], acViewPreview
ExitProc:
Exit Sub
ProcError:
Select Case Err.Number
Case 2501 ' No data or user cancels, so ignore this error.
Case Else
MsgBox Err.Number & ": " & Err.Description, vbCritical, _
"Error in cmdPreviewReport_Click Event Procedure..."
End Select
Resume ExitProc
End Sub
4.) Move the code intended for the NoData event procedure to the class
module associated with your report. See the code associated with the report
in my sample database.
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
__________________________________________
:
Thanks so much for all the information. After reading through your papers, I
realized that you diagnosed the problem correctly as being related to the No
Data property. The problem doesn’t occur within the report itself – it
happens when the user clicks on the desired report from a list box. When I
click on “Debug†in the error message, it takes me to the Print Preview code.
However I still get the ms error message as before. Here’s my code:
Private Sub Command4_DblClick(Cancel As Integer)
'Open the selected report in the Print Preview window
DoCmd.OpenReport [ReportListControl], acViewPreview
On Error GoTo ProcError
MsgBox "No records match the search criteria for this report.", _
vbInformation, "Project Database"
Cancel = True
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
"Error in NoData event procedure..."
Resume ExitProc
End Sub
What am I doing wrong?