Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Stop a report from Printing if No Data?? 1

Status
Not open for further replies.

Crauck

Programmer
Jul 26, 2002
24
US
I have a macro that imports data automatically, and then splits it up into different tables, then calculates inventory counts etc. and then finally prints out various reports. My problem is sometimes there is no data in certain tables but my report still prints (prints nothing but header info). I am trying to find a way to stop the report from printing if there is no data. I have found one way to do it in the actual report under NoData. But it then gives me a MsgBox saying that the OpenReport was cancelled. I don't really want any message, normally I can turn these off but I can't seem to get this one to turn off.
 
Function data_chk(rpt As Report)
'verifies that report has data
If rpt.HasData = False Then
Dim name_rpt As String
rpt.Visible = False
DoCmd.CLOSE acReport, rpt.Name
MsgBox "There was no information to print.", vbOKOnly + vbInformation, "NOTHING?"
End If
 
I'm sorry I not quite getting this. Could you spell it out just a little bit more?? Please!!
 
thread703-467180 looks like it has a good sub to run in the OnClick event (just drop the msgbox reference)
 
Within your macro, before you open the report do a SetWarnings False, then set it back to True afterwards. It has the same effect as On Error Resume Next/On Error Goto 0 within VBA i.e. ignores errors (as generated by setting Cancel = True within the NoData event)
 
Thanks for all the suggestions, but I actually came up with another way. I used:

Public Function Chkrpt()
Dim p As Variant

p = DLookup("Manual", "Mail")
If p > 0 Then
DoCmd.OpenReport "rptLabel File", acViewNormal
End If

End Function


Thanks Again!!
 
Maybe I'm missing something, but, if your On No Data event only contains this code:
Code:
Cancel = True
, that should work. I do this a lot and the user never receives a message box.
 
When I do it, it gives a message that the Open Report Action was cancelled.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top