Changing a subreport source object (1 Viewer)

Gkirkup

Registered User.
Local time
Yesterday, 20:54
Joined
Mar 6, 2007
Messages
628
I have a report on which I sometimes need to subsitute a different subreport. So in the main report detail, On Format event, I use the following code:

Me.[MySubformContainer].Source Object = Report.[MyNewSubform]

This does nothing, in fact the report doesn't print at all when this line is called. Is the syntax incorrect? I can't find any docs on resetting the Source Object, or how to do that.

Robert
 

vbaInet

AWF VIP
Local time
Today, 04:54
Joined
Jan 22, 2010
Messages
26,374
Try setting the name without the square brackets and enclose it in quotes:
Code:
Me.[MySubformContainer].SourceObject = [COLOR=Red][B]"[/B][/COLOR]Report.MyNewSubform[COLOR=Red][B]"[/B][/COLOR]
By the way, via what means are you setting it? In design view via a command button or are you using the Report View in Access 2007/2010?

Also noticed that Source Object should be without spaces too.
 

Gkirkup

Registered User.
Local time
Yesterday, 20:54
Joined
Mar 6, 2007
Messages
628
Thanks. I will try that. I will also make SourceObject one word - I tried it both ways.
I am using this in Access 2003 in an If/Then condition

Robert
 

vbaInet

AWF VIP
Local time
Today, 04:54
Joined
Jan 22, 2010
Messages
26,374
If you're still having problems, show us your code here.

By the way, are you setting it by opening the report in design view?
 

Gkirkup

Registered User.
Local time
Yesterday, 20:54
Joined
Mar 6, 2007
Messages
628
vba: That didn't work. I am scratching my head on this one. When this line is included, the 'Printing' box appears for a second, but the report doesn't print. I comment out the line and the report prints perfectly. Here is the actual code:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Forms]![3 SALE PICK TICKET]![ALTERNATESHIP] = True Then
' Alternative ship address
Me.[3 sector sale shipto subreport].SourceObject = "Report.3 Sector Sale Shipto Subreport"

End If
End Sub

I have temporarily set the source object to the 'regular' subreport, to rule out any problem caused by the new subreport.
Any ideas? I appreciate your assistance.

Robert
 

vbaInet

AWF VIP
Local time
Today, 04:54
Joined
Jan 22, 2010
Messages
26,374
Why are you trying to do it on the Format event? Why not do it before opening the report?
 

Gkirkup

Registered User.
Local time
Yesterday, 20:54
Joined
Mar 6, 2007
Messages
628
Good point. I will try that.

Robert
 

Gkirkup

Registered User.
Local time
Yesterday, 20:54
Joined
Mar 6, 2007
Messages
628
Yeah, that worked! At least the report printed, with the standard subreport. Now it should be a simple matter to change the subreport.
Thanks so much.

Robert
 

vbaInet

AWF VIP
Local time
Today, 04:54
Joined
Jan 22, 2010
Messages
26,374
You're welcome.

It was actually working but it's like subforms, it must have been that the first and/or last records didn't meet the criteria.
 

Users who are viewing this thread

Top Bottom