hide subreport in the report under condition

G

Guest

Hi,

I have a report that has a sub-report (sub-report1) in it. Based on the
value of a field say studID, i'd like to be able to hide/unhide the
sub-reports.

What i'd like to see in the report is
StudID 1
subreport1
StudID 3
StudID 4
StudID 5
StudID 6
and so on

Here is the code

Code:
Private Sub Report_Open(Cancel As Integer)
If Me.StudID > 2 and Me.StudID < 8 Then
Me.subreport1.Visible = False
Else
Me.subreport1.Visible = True
End If
End SubThe problem with the above code is that it says that StudID has no
value.

Then

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.StudID > 2 and Me.StudID < 8 Then
Me.subreport1.Visible = False
Else
Me.subreport1.Visible = True
End If
End SubThe problem with this is that the subreport1 appears after StudID is
1 (one) but i got nothing after StudID = 3.

I'd greatly appreciate your help.

Thank you in advance
 
M

Marshall Barton

Associates said:
I have a report that has a sub-report (sub-report1) in it. Based on the
value of a field say studID, i'd like to be able to hide/unhide the
sub-reports.

What i'd like to see in the report is
StudID 1
subreport1
StudID 3
StudID 4
StudID 5
StudID 6
and so on

Here is the code

Code:
Private Sub Report_Open(Cancel As Integer)
If Me.StudID > 2 and Me.StudID < 8 Then
Me.subreport1.Visible = False
Else
Me.subreport1.Visible = True
End If
End SubThe problem with the above code is that it says that StudID has no
value.

Then

Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If Me.StudID > 2 and Me.StudID < 8 Then
Me.subreport1.Visible = False
Else
Me.subreport1.Visible = True
End If
End SubThe problem with this is that the subreport1 appears after StudID is
1 (one) but i got nothing after StudID = 3.


The value of a field in the report's record source
table/query is not available in the report's Open event, so
your first try can't work.

A problem with the second try is that because of
CanGrow/CanShrink and other options, you can do anything
that affects the layout of a page in the Print event.

The code should work ok in the Format event of the section
containing the subreport:

Me.subreport1.Visible = (Me.StudID <= 2 Or Me.StudID >= 8)
 

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