Recordsource on Sub-report (1 Viewer)

MarionD

Registered User.
Local time
Today, 04:36
Joined
Oct 10, 2000
Messages
421
I start the printing of a report from a button on a form where certain options are set.

In the report I have a sub-report which acts as a letterhead. Depending on the choices made in the Form , I would like to change the record source of the sub-report (letterhead.)

My code I’m using is:
Dim sqlstr as string
Sqlstr= ”blablabla”
Reports![Mainreport]![subreport].report.recordsource=sqlstr
Or
Me.[subreport].report.recordsource=sqlstr

And this is my problem:

If I put the procedure in the OnOpenEvent of the Main report I get the error message - “invalid reference to a report” (directly translated from German – I’m not sure what the exact error message would be in English)

If I put it on onactivate or onopen of the sub-report I get the error message:-
“You can’t set the recordsource after you’ve started a print job.”

I can’t work out where to put the code!
Does anyone have an idea?
Thanks in advance.
Marion
 

MarionD

Registered User.
Local time
Today, 04:36
Joined
Oct 10, 2000
Messages
421
Hi again,
I still haven't solved my problem - perhaps I'm going about it in the wrong way - can anyone tell me if it's possible to change the recordsource of a sub-report ?

I have a table where the particulars of different day-care centres are stored. These are administered from a central office. Now when I print an account, I would like the particulars of the relevant day.care centres printed on top. In a pop up form, I choose which day care centre is needed and then click on button "Print" - at this point I would like to set the sub-report record source.
Would really appreciate some help if anyone has any ideas.
thanx
Marion
 
R

Richie

Guest
Can you not base the sub report on a query which references the form?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:36
Joined
Feb 19, 2002
Messages
43,392
If the subreport is properly linked (using the master/child link fields) to the main report, the subreport should be sychronized to the main report's filter. You shouldn't need to set it separately.
 

Keith P

Registered User.
Local time
Today, 04:36
Joined
Oct 11, 2000
Messages
122
I am not sure why you need a sub report to display a heading, assuming I understand your question correctly, why can you not have the heading incorporated into the report bearing in mind that you have report and page headers, plus group headers if you need them.
You could then control the header content on the onOpen event, e.g. if forms!myForm!careCentre = "CentreA" then me!myHeader = "Centre A Header Detail Here"
 

MarionD

Registered User.
Local time
Today, 04:36
Joined
Oct 10, 2000
Messages
421
Thanks so much for all the ideas. I know it takes time to solve someone else's problems and thats a commodity few of have! I appreciate the help.

I have solved the problem using a little advice from each of you! I use a query instead of an sql string. I set the parameter in the query "[carecentreID]=forms![dlgprintaccount]![CarecentreID]). It works fine now.
Keith - the reason I didn't put in the report header (actually my sub-report is in the header) is that the sub-report has the Day-care's logo etc... in it. I just thought it would be easier to maintain in a sub.report.

Thanks again to all
Till next time
Marion
 

Users who are viewing this thread

Top Bottom