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
newbie46Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbizupCommented:
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:
http://office.microsoft.com/en-us/access-help/order-of-events-for-database-objects-HP005186761.aspx

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.