Unanswered: Dynamically changing sub report formatting and binding
I have successfully written code that dynamically formats and binds a common "template" subform that I use to display/edit a wide variety of data. Why? well it reduces my form count for starters(to something manageable),allows me to control several form settings based on master table and lets me set up the many different forms I need quickly and easily just by setting a few parameters in the subform.tag. Ignoring the obvious question “why the hell would you …..” it actually work really well and ultimately will same me heaps of time.
I do this by adding a series subforms to a main form with the common template form as the sourceobject of each subform. The main form open event iterates through all the subforms and calls a sub on the template form that creates the dataset and binds and formats the template form to match the source data and format setting in the master table. The reason I use the main form open event is that it allows me to pass a parameter to the subform.form which I store in the subform control tag. The code to initiate the subform formatting looks something like.
Dim ctl As Control
For Each ctl In Me.controls
If ctl.ControlType = acSubform Then
The key bit is the call to the sub “bind”( ie ctl.Form.Bind ctl.Tag).
So after all that, my question is why can’t I do a similar thing with subreports? If I use the same approach from the report Open event (ie ctl.Report.Bind ctl.Tag) I get an error saying the “bind” sub is not available. I thought this was because the main report open event occurs before the subreport.report open event but this is not the case –it seem the error is caused by the compiler that doesn’t recognise the “bind” sub. If I use the activate event of the main report I can “see” the “bind” sub on the subreport but I get an error saying that I can’t change the record source property in print preview.