Problem with runtime recordsource assignment in subreport

  • Thread starter Savvoulidis Iordanis
  • Start date
S

Savvoulidis Iordanis

I have a main report (rpt1) with 2 subreport controls (subrep1 and subrep2
that share the same report object (rpt2).

Initially the report object rpt2 in the two controls, does not have any
query associated with it.

What I want in the main report's open event is to have the 1st subreport
control display the subreport,
using different parameters than the 2nd subreport control, but I get error
number 2455.

The open event of the main report (rpt1)

Private Sub Report_Open(Cancel As Integer)
me.subrep1.Report.RecordSource = "qry2" <<<< error 2455 here
me.subrep1.Requery
..
..
..
..
End Sub
 
M

Marshall Barton

Savvoulidis said:
I have a main report (rpt1) with 2 subreport controls (subrep1 and subrep2
that share the same report object (rpt2).

Initially the report object rpt2 in the two controls, does not have any
query associated with it.

What I want in the main report's open event is to have the 1st subreport
control display the subreport,
using different parameters than the 2nd subreport control, but I get error
number 2455.

The open event of the main report (rpt1)

Private Sub Report_Open(Cancel As Integer)
me.subrep1.Report.RecordSource = "qry2" <<<< error 2455 here
me.subrep1.Requery


Get rid of the Requery, it has no meaning in a report.

You're getting the error because the state of the subreport
is such that it's record source can not be changed at that
time. The only time you can set a (sub)report's record
source (and some other properties) is in its own Open event.
Furthermore, if the subreport is in a section (e.g. Detail)
that has more than one data record to display, you can only
set the subreport's record source the first time its Open
event fires.

Unfortunately, I can not think of a way for a report to
determine if it is being displayed in any particular
subreport control. Depending on what you're trying to
accomplish, one possible way to avoid this conundrum is to
forget about changing the record source and use the
subreport controls' Link Master/Child properties to filter
the data differently in the two instances.
 

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