Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

How do I pass a value from a Main report to its subreport?

I have a Main report which generates 20 different reports. Within Private Sub Report_OnOpen, a BuildTempTable sub is called with the type of report passed as an input parameter. (See code below). The record source for the Main report is the Temp table. The Main Report is grouped by ReportType. Within the footer section of ReportType, I need a subreport. This subreport's recordsource is set based on the ReportType being processed.

My question: How do I pass the ReportType to the subreport. I have set the Parent/Child connection between the Main/sub report to be ReportType. The subreport has processing within its Report_OnOpen event, dependent on the ReportType.

private Sub BuildTempTableForMainReport(Type as String)
if Type = "A" then
   db.execute "INSERT INTO TempTable (ReportType,......) VALUES ('" & Type & ......
elseif Type = "B" then
  db.execute "INSERT INTO Temp....
elseif .....

End if

Private Sub MainReport_OnOpen()

  call BuildTempTableForMainReport("A")
  call BuildTempTableForMainReport("B")

End sub

'''''''''''' Within subreport
private Sub SubReport_OnOpen()
if ReportType="A" then
  me.recordsource = .....
elseif ReportType = "B" then
  me.recordsource = ......
end if
1 Solution
The trouble you are running into likely has to do with Access's order of events.

Subreports (and subforms) load *before* their parent objects.  See this for details:

How are you informing your main report of the ReportType?

You will need to make that information available to your subreport *before* the main report loads.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now