Dynamically Changing Sub-Reports Source Object RRS feed

  • Question

  • I have a report, with several sub-reports, to print a form pre-filled with data. If no data exists in a sub-report, I still want the sub-report to print - without data - so it could be used as an input form. Specifically, I still want the labels and empty text boxes to print so they can be used to write information in them on the printed report.

    I have two sub-reports created: one to be used when there is data (it has a RecordSource, etc.) and one when there is no data (no RecordSource) with all the controls unbounded.

    I know I can put both sub-reports on the main report and select which one to display at runtime. If I do this, where would I put my code on the main form to select which one is visible? I know sub-reports are formatted before the main report but I'm just not sure where to put this code.

    What I'd really like to be able to do, if possible, is to dynamically select the sub-report's Source Object at runtime depending on whether or not there's data in the sub-report. If there is, then the regular sub-report (with the data) will be printed. If not, then I'd like the blank sub-report to be printed with just the labels and unbounded text boxes.

    Any ideas on the best way to do this? And, where would I put my code?


    Saturday, September 21, 2019 5:26 AM

All replies

  • Just set the RecordSource on the Open event.

    I am under the impression that is better to use the Open event of the parent report to set the Recordsource of subforms but do give it a try to see if you will put in the parent or on each of the sub reports.

    Saturday, September 21, 2019 6:40 AM
  • Any ideas on the best way to do this? And, where would I put my code?

    Hi WaterLover069,

    I have hardly any experience with Reports, but I would guess to put the code in the Open event of the Subform.

    My personal way of working is to use Forms for any user interaction, and Reports ONLY for static reporting, with no further user interaction. In the click event of the command button to open the report, you could check whether there are records to display. If yes, open the report; if no open a form for user input. Or some other way to achieve the same result.


    Saturday, September 21, 2019 8:19 AM