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!

Pass data unless subreport has no value

Status
Not open for further replies.

melaniecarr23

Programmer
May 2, 2005
79
US
I need to pass the totals from subreports to the main report, but if the subreport control has no data I need the control on the main report to return a 0 value.

Example: Subreport dd_report has a control ddtotal
subreport co_report has a control cototal
Subreport cash_report has a control cashtotal
On the main report, I would like to total all of these controls, but if one report has no data (which will be the case sometimes), I want the control on the main report to not give an error message because the control doesn't exist.

How can I do this?

Thanks!
 
Melanie
You can use the HasData property to check for an "empty" subreport.

For example, put an unbound control on your main report, and for its control source use an expression such as
Code:
=IIf([YourSubReportName].[Report].[HasData]=-1,[YourSubReportName].[Report]![YourSubReportTotalField],0)

The -1 is the Access value for True.
Tom
 
It's not working for me. I keep getting #Name? instead of the value I wanted. I have referenced data in subreports before, but any time I try using HasData with it I get problems.
 
Melanie
#Name would normally mean that you are trying to use a bound control.

Make sure that the control in the main report is unbound and then put what I suggested in it as the control source.

I use this all the time in an Invoice report. Here is the way I use it.
1. In the report footer for the subreport, I put a text box to give the totals for items in that subreport.
2. Then in the main report I put an unbound control which checks for HasData, to allow for empty subreports.


My subreport is called rptInvoiceDetails. The total box in the subreport's report footer is Text11. So here is the code in the unbound text box in the main report.
Code:
=IIf([rptInvoiceDetails].[Report].[HasData]=-1,[rptInvoiceDetails].[Report]![Text11],0)

Tom
 
I am using an unbound control. When I reference and a report exists, I'm fine. As soon as I try using HasData in the equation, I get errors. I just can't understand why it's not working with the HasData part in the formula.

Melanie
 
Melanie
Sorry...I have been travelling for a day and out of touch.

Are you using Access 2000 or 2003? I used 2003 for a while and found I had to add a further reference to make HasData work properly. If you are using 2003, let me know and I'll hunt up the solution.

Tom
 
Melanie
You can also try removing some of the brackets.

Try...
Code:
=IIf([YourSubReportName].Report.HasData=-1,[YourSubReportName].Report![YourSubReportTotalField],0)

Tom


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top