Conditional display of subreport

  • Thread starter Thread starter FergusonH
  • Start date Start date
F

FergusonH

Hi! I found some posting but can't quite get this to work (I'm a vba novice
so please bear with me).

I have a report (ReportA) with a subreport (SubA). I'm trying to SubA to
display only when the sum of amounts (control name: Text1) is greater than
0.00.

The subreport is in the detail section of ReportA. There are other
subreports too.

I'm trying to use the "Me.subreportcontrol.visible = (text1 >0)" but I'm
getting errors - do I put this code in the subreport or in the main report?

thanks!
 
FergusonH,
A very basic method is to Use the OnFormat event
for the Report A's Detail Section.

If Text1 > 0 Then
Me.SubreportControl.Visible = True
Else
Me.SubreportControl.Visible = False
End If
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
FergusonH said:
Hi! I found some posting but can't quite get this to work (I'm a vba novice
so please bear with me).

I have a report (ReportA) with a subreport (SubA). I'm trying to SubA to
display only when the sum of amounts (control name: Text1) is greater than
0.00.

The subreport is in the detail section of ReportA. There are other
subreports too.

I'm trying to use the "Me.subreportcontrol.visible = (text1 >0)" but I'm
getting errors - do I put this code in the subreport or in the main report?


If Text1 (a very poor name) is in the subreport's header or
footer section and has an expression that totals the
subreport amounts (e.g. =Sum(amount)), then the code in the
main report detail section's Format event could be:

Me.SubA.Visible = (Me.SubA.Report.Text1 > 0)

Make sure the main report detail section and the SubA
subreport **control** has its CanShrink property set to Yes.
 
Hi Al,

I'm sure it's user error but I can't get this to work.

In the main report, in the detail section, I clicked on properties, event,
on format...I used the code builder option and added the below:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Text14 > 0 Then
Me.subreportcontrol.Visible = True
Else
Me.subreportcontrol.Visible = False
End If

End Sub

I'm getting "Compile error: method or data member not found"

I tried swapping "subreportcontrol" with my sub report control name, but I'm
still getting an error.
 
Thank you! This worked!!!

I now have a blank page - because I put page breaks in the detail section of
the main report around each subreport.

Are there any quick fixes to that? Should I take the page breaks out of the
detail of main report and just put page breaks in the sub reports?

thanks!
 
Thank you Al, it was user error - I found the problem and fixed, my real
subreport has spaces and underscores in the name , so i had to put brackets
around it.
 
FergusonH said:
Thank you! This worked!!!

I now have a blank page - because I put page breaks in the detail section of
the main report around each subreport.

Are there any quick fixes to that? Should I take the page breaks out of the
detail of main report and just put page breaks in the sub reports?


PageBreak does nothing in a subreport so that won't solve
anything.

You can use a little more code in the main report's Format
event to turn a main report page break on or off when a
subreport does not have any data:

Me.pgBreak1.Visible = (Me.SubA.Report.Text1 > 0)
 
Back
Top