Hide detail based Sub

C

CJ

Hi Groupies

The detail section of my report contains a subreport. If the subreport has
no data I do not want the sub or the detail to print. The Visible property
for both the detail and the sub is currently Yes, but I have added the
following code to the Parent Detail section:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

docmd.Echo False
If Me!rsubHoursRemainingOT.Report.HasData Then
Me.Visible = True
Me!rsubHoursRemainingOT.Report.Visible = True
Else
Me.Visible = False
Me!rsubHoursRemainingOT.Report.Visible = False
End If
docmd.Echo True

End Sub

At this point, I still see the detail for every record but the subreport
shows up only when it has data, but I think it would do that anyway even
without the code.
If I set the visible property to No for both, then I don't see anything at
all, so I think that perhaps my code is not in the correct event, but I have
not had any luck anywhere else.

Help Please!!!
CJ
 
J

John Spencer

Me.Visible would affect the reports visibility. Why not just cancel the
entire section?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me!rsubHoursRemainingOT.Report.HasData Then
Cancel = False
Else
Cancel = True
End If

End Sub

An alternative would be to set the visible property of the detail SECTION to
true or false.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Me.Section(acDetail).Visible = Me!rsubHoursRemainingOT.Report.HasData

End sub
 
C

CJ

Excellent, thanks again John!
John Spencer said:
Me.Visible would affect the reports visibility. Why not just cancel the
entire section?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

If Me!rsubHoursRemainingOT.Report.HasData Then
Cancel = False
Else
Cancel = True
End If

End Sub

An alternative would be to set the visible property of the detail SECTION
to true or false.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Me.Section(acDetail).Visible = Me!rsubHoursRemainingOT.Report.HasData

End sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top