Subreport recordsource problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a report with two embedded subreports. The main report has the recordsource set in VB code of the on open event. If I define the recordsource for the two subreports using a query-designer query, all is well. But if I try to set either subreport recordsource in VB code of the on open event, I get an error when I move between pages of the report saying "You can't set the RecordSource property after printing has started." Why am I getting this error?
 
The reason why you receive the error is that Access is probably firing the
Open event of the subreport twice.

The first occurance fires *before* the main report opens, so any attempt to
reference anything in the main report fails.

The second occurance fires after the report is already in progress (as
non-sensical as that sounds), and so attempts to assign the recordsource in
this 2nd instance of Report_Open fails.

If what you are trying to do is independent of the main report, you may find
that the 1st occurance achieves what you need, and so you can tell your
error handler to ignore the error caused by the 2nd occurance.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

ctdak said:
I have a report with two embedded subreports. The main report has the
recordsource set in VB code of the on open event. If I define the
recordsource for the two subreports using a query-designer query, all is
well. But if I try to set either subreport recordsource in VB code of the
on open event, I get an error when I move between pages of the report saying
"You can't set the RecordSource property after printing has started." Why
am I getting this error?
 
Allen,
You're response made me do some more checking with some debugging stops at the On Open events of the main report and the two subreports. I discovered that the two subreports are opened immediately after the main report (as one would expect), then they are opened again whenever the user moves between report pages, which is rather odd. So what I did was to set a global variable to indicate that they had been opened initially, then a variable test in the On Open event of each subreport prevents execution of setting the RecordSource beyond the first time. This prevents the error message from occuring.

Thanks for getting me thinking and troubleshooting further.

ctdak
 
Back
Top