Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard mouse network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Access passing data from report to subreport

Reply  
Thread Tools
esmerelda's Avatar
Junior Member with 4 posts.
 
Join Date: Nov 2009
20-Nov-2009, 09:17 PM #1
Access passing data from report to subreport
I am trying to get some values from a report into the subreport. Although I receive no errors the values are Null in the subreport. Any assistance on where I am going wrong would be appreciated.

In the main report I have the following. The MsgBox print out correctly and the report displays the txtSelectedMonth and txtSelectedYear correctly (the values of x and y are set in Report_Open):
Private Sub ReportHeader_Format()
Me.txtSelectedMonth = x
Me.txtSelectedYear = y
MsgBox "In main_ReportHeader Month = " & x & "Year = " & y

End Sub

In the Subreport I have the following, both xx and yy are Null in the Msgbox print :
Private Sub Report_Open()
xx = Parent![txtSelectedMonth]
yy = Parent![txtSelectedYear]


MsgBox "In report open of Subreport Month = " & xx & "Year = " & yy

End Sub

I have also tried the assignments:
xx = Reports![My main report]!txtSelectedMonth
yy = Reports![My main report]!txtSelectedYear

They also still have xx and yy as Null in the msgbox printout.

Any suggestions greatly appreciated!
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
21-Nov-2009, 08:22 AM #2
Try this
xx = me.Parent![txtSelectedMonth]
yy = me.Parent![txtSelectedYear]

But put it in the Subform's Header or Detail "On Format" Event Procedure.

Another alternative is to put those values in the Queries that supply the Record Sources for the two reports. (You do have queries, as that is what they are for?)
__________________
OBP
I do not give up easily
esmerelda's Avatar
Junior Member with 4 posts.
 
Join Date: Nov 2009
21-Nov-2009, 12:23 PM #3
I added some msgbox statements in each of my subs and found that the order or execution was not what I expected. The order was
main report open
subreport open
main report_header
subreport report_header

I would have thought that it would have done both the main report open and report_header before moving on to the supreport open and report_header. What was happening was that since I can't set the txtfields until I am in the main report_header they were null (hadn't been set yet) when the subreport's report_open was executed.

My overall goal in this exercise is to have a main report call a form that asks the user for a month and year and then run multiple subreports (all with unrelated queries built in the report open and assigned via me.recordsource) using that month and year. The user only gets asked once and the subreports run contiguous on the page.

The only thing I can think of is to declare global variables in a module and refer to them. (Which I've never set up before but...)
OBP's Avatar
OBP OBP is offline
Computer Specs
Distinguished Member with 14,665 posts.
 
Join Date: Mar 2005
Location: UK
Experience: An old Basic Programmer
21-Nov-2009, 12:40 PM #4
Which is why you use the On Format event.
But there are other ways to pass the data to the Reports.
Is the data in XX & YY the data from the Form?
if so you can can use Forms![Formname]![Fieldname] in the Control Source of the Field.

Which version of Access do have?
Can you post a zipped copy of the database (less data) as an attachment?
__________________
OBP
I do not give up easily
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:19 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.