Hi Tom,
Sorry, I never use macros, so I don't know how/whether they offer any
conditional execution depending on error codes (I suspect they probably do).
If they do, you would use the Cancel error code (2501) from the report's On
No Data event to stop the SendObject action.
If you mean VBA code, rather than an actual macro, then one way of doing
this would be to put then DoCmd.SendObject statement in an If statement
which checks a flag set in the error handler after opening the report. The
code outline would be:
Private Sub YourExistingProcedureName()
Dim blnReportHasData as Boolean
On Error GoTo ErrorHandler
...
blnReportHasData = True
DoCmd.OpenReport ....
If blnReportHasData Then
DoCmd.SendObject ...
End If
...
Exit Sub
ErrorHandler:
If Err.Number = 2501 Then
blnReportHasData = False
Resume Next
End If
End Sub
You can't test for Err.Number in the If statement, since the Resume Next in
the error handler clears the error condition (ie. resets Err.Number to 0);
that's why I declare a variable for the flag (blnReportHasData) to use in
the If statement. Alternatively, you could remove all error handling and
then test for Err.Number in the main body of the code:
If Err.Number <> 2501 Then Docmd.SendObject ...
If you want advice on macro execution, I suggest you post a new question,
with a different (more appropriate) subject line.
HTH,
Rob