Article ID: 210285 - Last Review: October 11, 2006 - Revision: 2.2 HOW TO: Set Subreport's RecordSource Property at Run Time in Access 2000
This article was previously published under Q210285 On This PageSUMMARY
This article shows you how to ensure that the RecordSource property of a linked subreport is set only the first time that the Open event of the subreport is triggered. A linked subreport triggers the Open event several times, so you must make sure that the RecordSource property is set only once.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. You can set the RecordSource property of a subreport from its OnOpen event at run time only. At all other times, this property is read-only and cannot be modified. To create a report and subreport in which the RecordSource of the subreport is selected at run time, follow these steps: CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database. Create Two Example Queries
Create a Subreport
Create a Main Report
Use the Sub-report's OnOpen Event to Change Its RecordSource Property
Test the ReportOpen rptTestMain and notice that the customers listed are now those whose names begin with "B." NOTE: Microsoft Access checks the value of the static variable intCallCount. If intCallCount is zero, 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 intCallCount greater than zero.The variable intCallCount is declared in a Static statement because its value must be retained through several Open events. If it had been declared using the Dim keyword, its value would revert to 0 on each event and the code would fail. REFERENCESFor additional informationAbout Setting Report Properties at Run Time, click the article number below
to view the article in the Microsoft Knowledge Base:
114510
(http://support.microsoft.com/kb/114510/EN-US/
)
ACC: Limitations on Setting Report Properties at Run Time
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
