How do I determine what subreport control a subreport resides in?

N

Nyx37

I have a report with two subreports that are the same child report. I want
to be able to tell, within a subreports open event, which subreport control
it resides in. (i.e. if it's control 1 or 2) I need to do this so I can
reuse the same report in each subreport. Only the filter properties are
differnt.
 
D

Douglas J. Steele

Try this.

Set a global variable in your application, say glngSubreport. (Note that it
must be declared in a standalone module, so that it's accessible from both
the report and subreport)

In the report's Open event, assign the variable a value:

Private Sub Report_Open(Cancel As Integer)

glngSubreport = 1

End Sub

Add an unbound text box (temporarily) to your subreport. Let's assume you
named the control txtWhatSubreport. Put the following code in its Open
event:

Private Sub Report_Open(Cancel As Integer)

Select Case glngSubReportCount
Case 1 To 2
Me.txtWhatSubreport.ControlSource = "=" & glngSubreport
End Select

glngSubreport = glngSubreport + 1

End Sub

When you run the report, the two subreports will now have either 1 or 2 in
the text box you added.

That will not change unless you delete and readd the subreport to the form.

Note that the reason for limiting the code in the subreport's Open event to
only values of 1 or 2 is that the subreport's Open event fires for each
page, and you cannot change the ControlSource property of a report once it's
started to populate.
 
N

Nyx37

I got figured out. your code din't work but it helped me.
I placed a public varable named bytSrt in the master report and in the
subreport's open event, I incremented it.
 

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