Testing for no data in subreport

  • Thread starter Thread starter Damon Heron
  • Start date Start date
D

Damon Heron

Is there a way to test (from the main report, perhaps in a textbox) whether
a subreport has data or, if it closed because of no data?

Damon
 
Check the recordcount of the subreport's report's recordset.

If Me.SubReport.Form.RecordCount = 0 Then
' there are no records in the subreport
End If
 
Sorry..slight error in the previous reply:

Check the recordcount of the subreport's report's recordset.

If Me.SubReport.Form.RecordSet.RecordCount = 0 Then
' there are no records in the subreport
End If
 
That code causes access to crash. To explain further:

My subreport is based on a query. The subreport is also linked to the
mainreport by an ID. If no records match the ID, then subreport doesn't
stay open. To explain further, the subreport gives an onhand Beginning
inventory figure for various product classes and locations. The report is
only for a particular product class and location. So, if no product was on
hand at a particular location at the beginning of the month, then the
subreport closes and the area on the mainreport is blank. My problem is in
on the main reports footer. It calculates all the ins and outs for the
month, then shows end of month inventory. If subreport is blank, though, I
get #error# instead of correct figure. I have tried nz function, and
various other expressions, but nothing seems to work. Maybe there is a
better approach to a monthly report with beginning on hand and ending on
hand??

Thanks
Damon
 
The Correct syntax is something like:
=IIf(sbrptControl.Report.HasData, sbrptControl.Report!txtTotal, 0)
 
Try this syntax:

If Me.NameOfSubreportControl.Report.HasData = False
' No records
Else
' There are records
End If

The "NameOfSubreportControl" must be the name of the
CONTROL on the main report. It may or may not be the
same name as the subreport itself. Check that carefully.

See the Help File on "HasData" for more information.
 
This is an expression to use in the text box, correct?
so in my case, the sbrptControl is SumofGs, and it would read
=IIf(SumofGs.qryF7subReport.hasData, SumofGs.qryF7subReport!txtTotal, 0)

and the txtTotal is on the main report? This causes Access to ask for
parameter of "SumofGs.qryF7subReport".
forgive my stupidity -I don't get it.

Damon
 
sbrptControl is the name of the subreport embedded in the main report. It is
not the name of a text box, it is the name of the control that is the
subreport.
 
thanks for all your help, Duane and Jeff and Ken. I musta had brain freeze
last nite, as I couldn't get it to work. But finally solved my syntax, and
it works like a charm.

Damon
 
No problem Damon, glad to help.
Good to hear you have it working fine now.
Sometimes getting just the right syntax is half the battle!

"Brain freeze"?
Yep, been there.
Actually I tend to think of my brain as one big "Slurpee" all the time.
:-)
 
Back
Top