Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    subreport - change control source via VBA (Acc 97 SR2)

    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 = <valid report name>
    rptPreloadNote.ControlSource = sReportName

    to no avail. Nothing appears on the report. Please help -- thanks.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: subreport - change control source via VBA (Acc 97 SR2)

    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.
    Charlotte

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: subreport - change control source via VBA (Acc 97 SR2)

    Thanks very much. Worked exactly like you said.

    <soapbox>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 </soapbox>

    Thanks again.
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: subreport - change control source via VBA (Acc 97 SR2)

    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. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> 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 ....
    Charlotte

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: subreport - change control source via VBA (Acc 97 SR2)

    Arghhh... I keep putting my foot in my mouth. Gonna get boot tracks on my tongue. [img]/forums/images/smilies/sad.gif[/img] 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...
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

Posting Permissions

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