ID: Q154573
The information in this article applies to:
Advanced: Requires expert coding, interoperability, and multiuser skills.
The order of report event procedures change when you open an "instance" of a report.
When opening an "instance" of a report, the OnOpen event of the report occurs after the report has already bound to the data or recordset for the report. Typically, the OnOpen event for reports occurs before the report has bound to the data or record source, allowing the option of changing the RecordSource property for the report from this event.
Microsoft has confirmed this to be a problem in Microsoft Access 7.0. This problem no longer occurs in Microsoft Access 97.
When a report is opened from the Database window, the OnOpen event changes the record source to another table . When an additional report instance is called from a function, like the one below, an error occurs:
Run-time error '2191'
You can't set the RecordSource property after printing has started.
Solution
Try setting this property from the OnOpen event.
This article assumes that you are familiar with Visual Basic for
Applications and with creating Microsoft Access applications using the
programming tools provided with Microsoft Access. For more information
about Visual Basic for Applications, please refer to the "Building
Applications with Microsoft Access for Windows 95" manual.
1. Open the sample database Northwind.mdb
2. Create a copy of the Employees table, and then save it as 2ndEmployees.
3. Edit the data for the 2ndEmployees table (to distinguish it from the
first copy).
4. Using the AutoReport Wizard, create a new report based on the Employees
table, and save it as MyReport.
5. Open the report, MyReport, in Design view and from the OnOpen event,
change the report's RecordSource property as follows:
Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = "2ndEmployees"
End Sub
6. Close and save the report.
7. In a new module create the following function to open a new instance
of the report:
Public Function CreateNewReportInstance()
Static r As Report
Set r = New Report_MyReport
r.Visible = True
End Function
8. Run the function from the Debug Window and note that the error message
occurs.
For more information about creating multiple instances of an object, search on "What's new," using the Microsoft Access 7.0 Answer Wizard. Click the topic "What's new for Developers: Overview," click "Programming with Forms and Reports," and then view "Creating an Instance of a Form."
Keywords : kbprg PgmObj
Version : 7.0
Platform : WINDOWS
Hardware : x86
Issue type : kbbug
Solution Type : kbfix
Last Reviewed: August 29, 1997