ACC2: Empty Recordset Report Hangs with Group KeepTogetherLast reviewed: May 14, 1997Article ID: Q114549 |
The information in this article applies to:
SYMPTOMSModerate: Requires basic macro, coding, and interoperability skills. Microsoft Access stops while you are previewing a report and may mark the database as corrupted. Running Repair Database on the database eliminates the error message that states that the database is corrupted.
CAUSEMicrosoft Access can stop unexpectedly while you are previewing a report if the report is based on an empty recordset and the group KeepTogether property is set to With First Detail or Whole Group. This is a known problem with "retreating" in Microsoft Access version 2.0 reports. "Retreating" refers to returning to an earlier report section in order to determine where certain controls and sections are on a report, and whether they will fit in a given space. Examples of retreating include:
RESOLUTIONTo avoid this problem, test the report's underlying recordset to see if data is returned. If no data is returned, use the CancelEvent action to stop the report from processing. Two methods for avoiding the problem are described below.
Method 1Use this method when the report is based directly on a table or on a query that does not have parameters. Call the following Sub procedure from the report's OnOpen property:
Sub Report_Open (cancel As Integer) If IsNull(DLookup("<AnyFieldInQuery>","<QueryName>")) Then DoCmd CancelEvent End If End Sub Method 2Use this method if the report is based on a parameter query. The query must be open, with the parameter values filled in, before the number of records in the recordset can be referenced. Use the following sample code to cancel the report if the recordset is empty. This sample code references two date parameters. The key is to have the parameters filled in with values.
Sub Report_Open (Cancel As Integer) Dim MyDb As Database, MyQuery As QueryDef, DataRecs As Recordset Set MyDb = DBEngine.Workspaces(0).Databases(0) Set MyQuery = MyDb.QueryDefs("QueryName") MyQuery("Beginning Date:") = #1/1/96# ' or Forms!FormName![Control] MyQuery("Ending Date:") = #1/3/96# ' or Forms!FormName![Control] Set DataRecs = MyQuery.OpenRecordset() If DataRecs.EOF Then DoCmd CancelEvent DataRecs.Close MyQuery.Close End Sub STATUSMicrosoft has confirmed this to be a problem in Microsoft Access version 2.0. This problem no longer occurs in Microsoft Access version 7.0.
MORE INFORMATION
Steps to Reproduce ProblemWARNING: Following these steps causes Microsoft Access to stop. Be sure to save any work in progress before following these steps.
REFERENCESFor more information about the Retreat event, search for "Retreat," and then "Retreat Event" using the Microsoft Access Help menu.
|
Additional query words: hang
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |