Consulting

Results 1 to 3 of 3

Thread: Solved: Change recordsource of subreport when opening report?

  1. #1

    Solved: Change recordsource of subreport when opening report?

    Hi,

    I'm trying to change the recordsource of my subreport from the main report when i open the main report. Access is telling me that I "entered an expression that has an invalid reference to the property form/report". I am following the traditional subreport reference logic but think my syntax might be off?

    Here is what I'm using:
    Reports!rptProgramDetail!ProgramIssuesRisks.Report.RecordSource = FullString

    Main Report: rptProgramDetail
    Main Control with Subreport object: ProgramIssuesRisks

    Any idea what I'm doing wrong?

    Thanks!
    Hathman

  2. #2

    Solved!

    I just found my solution on the Microsoft site. Prior to trying to set the recordsource from the main form I was trying to set it in the subreport. This caused an error because it was being fired every time a new detail record was found. So I moved the code to the main report and was having the trouble mentioned above. The below code fixes my original issue of establishing the recordsource only once from within the subreport. Here is an excerpt right from Microsoft:

    Use the following sample Visual Basic code in the OnOpen event procedure of a subreport to set the RecordSource property the first time that the Open event is triggered and not thereafter:
    Static CallCount As Long If CallCount = 0 Then Me.RecordSource = "MyCustomRecordSource" CallCount=CallCount+1

    The Visual Basic code checks the value of the static variable CallCount. If CallCount is zero, then this is the first time the Open event is triggered, so the code sets the RecordSource property. Subsequent calls to the Open event will have a value of CallCount greater than zero.

  3. #3
    VBAX Newbie
    Joined
    Dec 2013
    Posts
    1
    Location
    Quote Originally Posted by Hathman View Post
    This caused an error because it was being fired every time a new detail record was found. So I moved the code to the main report and was having the trouble mentioned above. The below code fixes my original issue of establishing the recordsource only once from within the subreport.
    I never would've thought that was the problem. Makes sense!
    I've had various ways of getting around this over the years...this is much easier!
    Thanks for finding the solution.

Posting Permissions

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