• subreport – change control source via VBA (Acc 97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » subreport – change control source via VBA (Acc 97 SR2)

    Author
    Topic
    #357762

    the main report contains a subreport control named rptPreloadNote, for which I want to be able to specify the name of the report. Depending on circumstances, different reports will be displayed. In the Access Properties window, the report name is listed as “control source”, but I can’t find a comparable place in the object. I tried:

    sReportName =
    rptPreloadNote.ControlSource = sReportName

    to no avail. Nothing appears on the report. Please help — thanks.

    Viewing 0 reply threads
    Author
    Replies
    • #532170

      What you want is the SourceObject property of the subreport control, not the controlsource of the subreport itself. If you have a subreport control called rptPreloadNote, then you should be able to change the actual subreport that’s loaded into it like this:

      Dim srpt As SubReport
      Set srpt = Me.rptPreloadNote
      srpt.SourceObject = sReportName

      Be aware, though, that I haven’t tested this on reports, although I use the technique frequently on subforms.

      • #532179

        Thanks very much. Worked exactly like you said.

        The part that had me confused is that “SourceObject” does not show up on the IntelliSense list of properties for the object. If it had been on the list, I would have tried it by chance. Nor does it appear in the Object Browser in the Access Library for either the Report or Subreport Class. That being the case, how does one know about the SourceObject property?

        I’ve never been able to figure out a good method for looking for properties that I am sure *must* exist somewhere, but I don’t know what object to look under

        Thanks again.

        • #532180

          It is confusing, I agree. The same thing happens when you use the controltype property of a control. If it seems logical, sometimes, you just have to try it to see what happens. shrug Reports share a lot of characteristics of forms, and you can even embed one in the other, so if it works in a form, it’s at least worth a try in a report.

          Intellisense is a somewhat recent addition to Access VBA, so maybe I’m not as reliant on it as those who don’t remember version 1.0, 1.1, 2.0 ….

          • #532181

            Arghhh… I keep putting my foot in my mouth. Gonna get boot tracks on my tongue. It *is* listed as “Source Object” in the properties sheet — and your solution was just to remove the space. Funny, I could have sworn that I tried that name first, and it did not work. Guess I was mistook!

            BTW — I still have my Access 1.0 and 1.1 floppy disks on the shelf for nostalgia purposes…

    Viewing 0 reply threads
    Reply To: subreport – change control source via VBA (Acc 97 SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: