Changing ControlSource property on a subform

R

Rod

The OnOpen event for a report reassigns the .ControlSource property for a
given bound control based on certain criteria. The subform MyChild sits in
the Report Footer:

With "Reports!Report"
If myVar = 1 Then
!myField.ControlSource = "ChangeControlSource"
!myChild!myField.ControlSource = "ChangedControlSource" <= ERROR HERE
End If
End With

(I know I am not properly setting a control variable for the With statement
- in my actual code I am).

The error message tells me I am using an invalid reference when trying to
change the .ControlSource property for the myField control on the subform
myChild. I assume this is because, on the OnOpen event for the parent report,
the subreport is not yet open.

If I try and reassign Reports!Report!myChild!myField.ControlSource in the
OnOpen event of the myChild subform, I am told I cannot change the
..ControlSource property in print preview or once printing has started.

How would I change the .ControlSource of a control in a subreport (prior,
obviously, to OnFormat or OnPrint or the parent report)?

Thank you
 
K

Klatuu

You cannot make changes to a report that is not open. If you are using 2003,
the OpenReport method has an OpenArg property like forms, you could pass it a
value and set the controlsource in the form's open event. Or, you can put a
hidden control on your form that the report can use to set the controlsource.
 
R

Rod

Thanks, Klatuu, but not quite what I was looking for - perhaps I didn't make
myself clear:

The report isn't closed, it is being opened - the OnOpen event. I can make
changes to it, and am able to change the .ControlSource property for the
parent report. It's the child report I need to change as IT opens but before
the parent report locks down the .ControlSource property, thinking the report
now previewed or printing.

Or, more simply, how do I change the .ControlSource property on a subreport,
irrespective of the timing?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top