How can I make my Report Print Only when...

DaniBoy

Registered User.
Local time
Today, 23:14
Joined
Nov 18, 2001
Messages
174
Hello, I have some reports that I need printed only when there is data for them. Right now when I print a report, it prints the reports labels with no data in it. How could I fix this problem so that I will only print when there is data for that report.

Thanks
Daniel
 
Use the No Data event of the report to display a message box and cancel the event
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for the period you have selected", vbOKOnly

Cancel = True

End Sub
 
ok, i did it with the nodata event. now am actualy opening the report from a code on a form button, the code I used for this was the next one:

Private Sub TestNoData_Click()
On Error Resume Next
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear
End Sub

But I still get the empty Data Report, what am I doing wrong? How could I send this Database to someone so they could see what am trying to do?!!
Thanks
 
This code ought to work!!

Dim MyRS as Recordset
Dim MyRecs as single
set MyRS = Currentdb.OpenRecordset("Table/Query feeding report")
MyRecs = MyRS.RecordCount
If MyRecs = 0 then
else
DoCmd.OpenReport "SomeReport", acViewPreview
end if
MyRS.Close

HTH
 
I suspect your error handling is preventing the no data event try this code
Const ConErrRptCanceled = 2501
Private Sub Preview_Click()
' Preview report.
Dim strDocName As String
On Error GoTo Err_Preview_Click


strDocName = "YourRpt"
DoCmd.OpenReport strDocName, acViewPreview


Exit_Preview_Click:
Exit Sub

Err_Preview_Click:
If Err = ConErrRptCanceled Then
Resume Exit_Preview_Click
Else
MsgBox Err.Description
Resume Exit_Preview_Click
End If
 

Users who are viewing this thread

Back
Top Bottom