How to change the RecordSource for a subReport

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon van Beek

    How to change the RecordSource for a subReport

    Dear reader,



    How to change the RecordSource for a subReport.



    For forms the syntaxes is:

    Forms!MainForm! SubForm.Form.Re cordSource = "QueryX"



    But for a report the following syntaxes is not working:

    Reports!MainRep ort!SubReport.R eport.RecordSou rce = "QueryX"



    Is there a possibility to change the RecordSource for a subReport in the
    same way as for subForm?



    Thanks for any help.

    Kind regards,

    Simon


  • Larry Linson

    #2
    Re: How to change the RecordSource for a subReport

    Let's start back with terminology . . . just as there is no Access object
    called a Subform, there is no Access object called a Subreport. There are
    Subform Controls which can appear on either a Form or a Report, and
    Subreport Controls which can appear only on Reports.

    Subform and Subreport Controls do not have a Record Source, they have a
    Source Object... which can be a Form, Report, or Datasheet. But when you
    imbed a Form or Report in a Subreport Control, as far as I know, it's Record
    Source can only be changed in its Open Event.

    And, I have never tried to jump through the hoops to force code in the Open
    Event of a Report in a Subreport control to execute to change its Record
    Source.

    I would never have considered trying it in either the Format or Print event
    of the Detail Section in which the Subreport Control is located... I would
    have just assumed that it would not work.

    If you cannot synchronize the data between the Detail and the Report in the
    Subreport Control using the LinkChildFields and LinkMasterField s of the
    Subreport Control, I suspect you will have to find another approach to what
    you want to do...

    It might be possible to create a query joining what you are using as the
    Record Source of the Main Report and the Record Source of the Report in the
    Subform Control, and use Sorting and Grouping, and properties (e.g.,
    show/don't show duplicates) to control what is actually printed.

    Access reporting is really quite flexible, all things considered... this is
    my 50th year in the computer business, and I've never found a more capable,
    easier-to-use report generator on mainframes, minicomputers, or
    microcomputers than the one provided by Access.

    Some believe SQL Server Reporting Services to be as good, or better -- but,
    of course, that would require you be using some flavor of SQL Server as your
    data store.

    Larry Linson
    Microsoft Office Access MVP

    "Simon van Beek" <SvanBeekNL@Ver satel.nlwrote in message
    news:4921c18b$0 $22828$bf4948fe @news.tele2.nl. ..
    For forms the syntaxes is:
    Forms!MainForm! SubForm.Form.Re cordSource = "QueryX"
    >
    But for a report the following syntaxes is not working:
    Reports!MainRep ort!SubReport.R eport.RecordSou rce = "QueryX"
    >
    Is there a possibility to change the RecordSource for a subReport in the
    same way as for subForm?

    Comment

    • bobh

      #3
      Re: How to change the RecordSource for a subReport

      One idea might be to use the 'openargs' option as in

      DoCmd.OpenRepor t "rptname", , , , , QueryX

      then in the report open event add the code

      me.recordsource = me.openargs

      bobh.


      On Nov 17, 2:16 pm, "Simon van Beek" <SvanBee...@Ver satel.nlwrote:
      Dear reader,
      >
      How to change the RecordSource for a subReport.
      >
      For forms the syntaxes is:
      >
      Forms!MainForm! SubForm.Form.Re cordSource = "QueryX"
      >
      But for a report the following syntaxes is not working:
      >
      Reports!MainRep ort!SubReport.R eport.RecordSou rce = "QueryX"
      >
      Is there a possibility to change the RecordSource for a subReport in the
      same way as for subForm?
      >
      Thanks for any help.
      >
      Kind regards,
      >
      Simon

      Comment

      • Steve

        #4
        Re: How to change the RecordSource for a subReport

        Open your main report in design view. Click on the subreport box control)
        that holds your subreport. Open properties, go to the Other tab and see
        what the name is of the subreport box is. Let's say the name is
        SimonVanBeek. Change your code to:

        Reports!MainRep ort!SimonVanBee k.Report.Source Object = "QueryX"

        If you are changing the source object, most likely you need to change the
        LinkMaster and LinlChild properties too!

        Steve


        "Simon van Beek" <SvanBeekNL@Ver satel.nlwrote in message
        news:4921c18b$0 $22828$bf4948fe @news.tele2.nl. ..
        Dear reader,
        >
        >
        >
        How to change the RecordSource for a subReport.
        >
        >
        >
        For forms the syntaxes is:
        >
        Forms!MainForm! SubForm.Form.Re cordSource = "QueryX"
        >
        >
        >
        But for a report the following syntaxes is not working:
        >
        Reports!MainRep ort!SubReport.R eport.RecordSou rce = "QueryX"
        >
        >
        >
        Is there a possibility to change the RecordSource for a subReport in the
        same way as for subForm?
        >
        >
        >
        Thanks for any help.
        >
        Kind regards,
        >
        Simon
        >
        >

        Comment

        Working...