PC Review


Reply
Thread Tools Rate Thread

Changing a subreport recordsource

 
 
=?Utf-8?B?TmV2aWxsZVQ=?=
Guest
Posts: n/a
 
      10th Jun 2005
I have a report containing 13 subreports. Which subreports print is
determined by a form with 13 checkboxes. Tick the box, and the subreport's
visible property is set to true. The visible property is set by the reports
open event and works fine.

When I run the report, and try to print to Word I get an error message that
there are too many databases open. To overcome this I thought I would change
the recordset property of the subreports not required to blank so they would
not open a new query. If it is true the recordsource of the subreport is
changed to a query name.

If Forms![frmProjPlanRptSelector]![chkProjDetails] = True Then
Me!rptPPProjectSub.Report.RecordSource = "qryPPProjectSubreport"
Me![rptPPProjectSub].Visible = True
Else
Me![rptPPProjectSub].Report.RecordSource = ""
Me![rptPPProjectSub].Visible = False
End If

When I run it, the second line causes the following error. "Error 2455 You
entered an expression that has an invalid reference to the property
form/report"

What am I missing?

 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      10th Jun 2005
NevilleT wrote:

>I have a report containing 13 subreports. Which subreports print is
>determined by a form with 13 checkboxes. Tick the box, and the subreport's
>visible property is set to true. The visible property is set by the reports
>open event and works fine.
>
>When I run the report, and try to print to Word I get an error message that
>there are too many databases open. To overcome this I thought I would change
>the recordset property of the subreports not required to blank so they would
>not open a new query. If it is true the recordsource of the subreport is
>changed to a query name.
>
> If Forms![frmProjPlanRptSelector]![chkProjDetails] = True Then
> Me!rptPPProjectSub.Report.RecordSource = "qryPPProjectSubreport"
> Me![rptPPProjectSub].Visible = True
> Else
> Me![rptPPProjectSub].Report.RecordSource = ""
> Me![rptPPProjectSub].Visible = False
> End If
>
>When I run it, the second line causes the following error. "Error 2455 You
>entered an expression that has an invalid reference to the property
>form/report"



The main report opens before the subreports, so it's too
soon to set a subreport's properties from the main report's
Open event (and any other main report event is too late).

Bottom line is that the only place you can do this is in
each subreport's Open event.

Unfortunately that's not the whole story. If there will be
more than one instance of the subreport (e.g. it's in the
detail section), then you have to add additional code to
make sure you only set the record source once. Fortunately,
that's pretty easy:

Static Initialized As Boolean
If Not Initialized Then
'do your thing here
Initialized = True
End If

One additional thought, it has been reported(?) that Access
might look at the record source before the open event. If
you see anything strange, try setting the subreport's
RecordSource to blank in design view so Access can't even
attempt to start processing it before you decide what to do
with it.

--
Marsh
MVP [MS Access]
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing a Subreport's Recordsource via a Form BruceF Microsoft Access Form Coding 1 17th Dec 2007 08:23 PM
Changing Recordsource Property in subreport =?Utf-8?B?Q3Jvc3No?= Microsoft Access Reports 3 12th Jun 2007 07:18 PM
changing recordsource of subreport =?Utf-8?B?bmdhbg==?= Microsoft Access Reports 0 7th Sep 2005 01:22 AM
Changing a subreport's RecordSource in code Rob Rutherford Microsoft Access Reports 2 22nd Nov 2004 09:10 AM
Subreport's RecordSource Todd Microsoft Access ADP SQL Server 2 24th Nov 2003 04:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:23 AM.