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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Sub Reports in Report - On No Data I don't want it to print

Status
Not open for further replies.

ronis

Programmer
Jul 14, 2000
9
US
I have a report that has 2 sub reports - from two seperate queries. I need a way to tell the report that if both sub reports do not have any data, I do not want it to open or print. I am using Access 2000 and have tried the No data command on the sub reports as well as the actual report.

Any help will be greatly appreciated!

Thank.
 
My approach would be to use something like this in the main report OnOpen() event

Dim db as database
Dim rs as recordset

set db = dbengine(0)(0)
set rs = db.OpenRecordset("Select Count(*) from [QueryThatSubReportUses]")

if rs(0) = 0 Then [red]'Count is zero(0) records.[/red]
Cancel = True [red]'Cancel report.[/red]
msgbox "No Records ...", vbyesonly + vbinformation
End IF

End Sub

...another way would be:

Create a Global boolean variable called "boolNoData", in your sub report(s).

In the sub report(s), 'Report_NoData()' event add the code...
boolNoData = True

In the main report 'OnOpen()' Event add the code...
Private Report_OnOpen(Cancel as integer)

if(Reports![MainReportName]![SubReportName].boolNoData) then
DoCmd CancelEvent
'or, Cancel = Tue
End If
End Sub
Amiel
amielzz@netscape.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top