Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    2

    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.

    mainForm_open()
    Dim ctl As Control
    For Each ctl In Me.controls
    If ctl.ControlType = acSubform Then
    ctl.Form.bind ctl.Tag
    End If
    Next

    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.

    Any suggestion how I get around this problem?

  2. #2
    Join Date
    Feb 2004
    Location
    Canada
    Posts
    133
    Try the Format event of your Detail section (or header or footer sections).

  3. #3
    Join Date
    Nov 2006
    Posts
    2
    Thanks for the suggest but unfortunately it didn't work. By the time the format event fires it is not possible change the subreport.report recordsource.

    I have found a way around the problem but - it ain't pretty.

    I also found that a report doesn't appear to have a load event. I think if it did I wouldn't have this problem because I could call a sub on the subreport from the load event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •