How to change the source object of a subreport? (1 Viewer)

FISHiEE

Fish obsessive
Local time
Today, 22:19
Joined
Nov 12, 2004
Messages
86
Hi,

I have a report, within which is a subreport. I would like to be able to change the source object of that subreport to different forms depending on the status of one of the fields of the parent form record.

Basically this main report prints quote details of doors. I would like to display a different subform with different info for a fire door than I would for a ventilated door for example.

The piece of code I am using is as follows:

If [Door Part Number] Like "B*" Then
Me.frm_BDoorDetails.SourceObject = "rpt_Quote/AckBDoor"
Else
Me.frm_BDoorDetails.SourceObject = "rpt_Quote/AckFirelock"
End If

I am running this code on the OnFormat event of the detail record of the parent report. However, when I run the report I get the following error message:

"You can't set the Source Object property in print preview or after printing has started"

Maybe I am running the code on the wrong event?

If anyone can help me out with this I would be eternally grateful!

Thanks in advance

John
 

Bat17

Registered User.
Local time
Today, 22:19
Joined
Sep 24, 2004
Messages
1,687
I dont think that Access is going to let you switch sub-reports record by record. What you probably can do is use both reports and use their Visible property to hide/show as required. Can Grow/Shrink should take care of the gaps.

HTH

Peter
 

FISHiEE

Fish obsessive
Local time
Today, 22:19
Joined
Nov 12, 2004
Messages
86
In the help file it says it is possible to change the source but it doesn't say on what events thuis is possible.

If anyone knows for what events this is possible Imight be able to somehow get it to work. If not the visible/not visible option I can do though it means about a dozen hidden subreports which isn't so great. Also for the report to look correct they would have to all be placed one on top of the other unless anyone knows a better way to do it?
 

Bat17

Registered User.
Local time
Today, 22:19
Joined
Sep 24, 2004
Messages
1,687
You can probably change it on the open Event for the report but that is a once per use event. do you need to switch subreports during the print job, ie. one print out can use several subs?

The can grow/shrink should let you place the subreports one after another and hide the gaps atomaticaly for you.

Peter
 

FISHiEE

Fish obsessive
Local time
Today, 22:19
Joined
Nov 12, 2004
Messages
86
The report could quite possibly use a different subreport for each page.

The Cangrow/Canshrink property doesn't help as there is text in the subreport that isn't drawn through from the report the source query. I could I suppose blank that text out if that particular subreport isn't required but that's a lot of work and quite messy.
 

Users who are viewing this thread

Top Bottom