Don't print a report if no data.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some month end reports that when printed have no data, this is ok as
some of the reports will not have data. I'm wondering if there is anyway to
not print a report if there is no data available?
Thanks Tom
 
Set the Cancel argument of the report's NoData event procedure to True ...

Private Sub Report_NoData(Cancel As Integer)

Dim strPrompt As String

strPrompt = "There is currently no data for this report."
MsgBox strPrompt, vbOkOnly
Cancel = True

End Sub

You'll also need to trap error 2501 (action cancelled) in the code that
opens the report ...

Private Sub cmdPrint_Click()

On Error GoTo ErrorHandler
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.OpenReport "rptWhatever", acViewPreview

ExitProcedure:
On Error GoTo 0
Exit Sub

ErrorHandler:
If Err.Number = 3270 Then
MsgBox "Could not save record.", vbOkOnly
ElseIf Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description, vbOkOnly
End If
Resume ExitProcedure

End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top