Testing for no data in subreport

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
 
K

Ken Snell [MVP]

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
 
K

Ken Snell [MVP]

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
 
D

Duane Hookom

The Correct syntax is something like:
=IIf(sbrptControl.Report.HasData, sbrptControl.Report!txtTotal, 0)
 
J

Jeff Conrad

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.
 
D

Damon Heron

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
 
D

Duane Hookom

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.
 
D

Damon Heron

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
 
J

Jeff Conrad

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.
:)
 
Top