Microsoft KB Archive/154573

= ACC95: Opening Multiple Instances of Report Binds Data Too Soon =

Article ID: 154573

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 95 Standard Edition

-



This article was previously published under Q154573





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



STATUS
Microsoft has confirmed this to be a problem in Microsoft Access 7.0. This problem no longer occurs in Microsoft Access 97.



MORE INFORMATION
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.

Steps to Reproduce Problem
 Open the sample database Northwind.mdb Create a copy of the Employees table, and then save it as 2ndEmployees. Edit the data for the 2ndEmployees table (to distinguish it from the first copy). Using the AutoReport Wizard, create a new report based on the Employees table, and save it as MyReport.  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  Close and save the report.</li>  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 </li> Run the function from the Debug Window and note that the error message occurs.</li></ol>

<div class="references_section">