ACC2000: "#ERROR" Message When Referencing Subreport Controls

ID: Q208718


The information in this article applies to:


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).

If you reference a subreport control from a main report when the subreport does not return any matching records, you may receive the following message

#ERROR
for the referenced subreport control.


CAUSE

When the subreport has no data, it is not available. Referencing an empty subreport results in an invalid operation.


RESOLUTION

Make sure that subreport fields referenced in a main report contain data by adding a function to test for this condition. See the "Steps to Reproduce Behavior" and "Steps to Work Around Behavior" sections later in this article for an example of such a function.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Microsoft Access and open the sample database Northwind.mdb.


  2. Create the following query based on the Customers table:
    
       Query: Sorter
       -------------------
       Type: Select Query
    
       Field: CompanyName
       Criteria: Like "P*"
    
       Field: CustomerID 
    Save the query as Sorter. Note that this query limits the recordset only to customer records beginning with the letter "P" and includes a customer with no orders.


  3. Create a new report based on the Orders table and name it SubRpt.


  4. Drag the Freight field to the detail section of the subreport. In the report footer section, add a text box and set the control's properties as follows:
    
       ControlSource: =Sum([Freight])
       ControlName: TotFreight 
    The subreport prints the detailed freight items with a grand total for all freight charges.


  5. Create a new report based on the Sorter query and name it Main Report.


  6. On the View menu, click Sorting And Grouping. Click CompanyName under the Field/Expression box and set the GroupHeader property to Yes.


  7. Drag the CompanyName field to the new CompanyName header section.


  8. Drag the SubRpt subreport from the Database window to the detail section of Main Report.


  9. Add a text box and set its ControlSource property as =([SubRpt].[Report]![TotFreight]). Set the Caption property of the label as Total Order Amount Per Customer:.


  10. Set both the LinkMasterFields and the LinkChildFields properties for the subreport control to CustomerID. Setting these properties filters the subreport to display the Freight charges for each customer.


  11. Preview the report. Note that "#ERROR" is displayed for the references to the subreport control for Paris Specialties, which has no orders.


Steps to Work Around Behavior

To test that subreport fields referenced in a main report contain data, follow these steps:
  1. Replace the line
    
       =([SubRpt].[Report]![TotFreight]) 
    in step 9 above with the following line:


  2. 
       =IIF([SubRpt].Report.HasData=True, [SubRpt].Report![TotFreight], 0) 
  3. Preview the report.


Note that a zero value is displayed for Paris Specialties instead of the "#ERROR" message. The HasData property of the subreport returns True or False. You can use this property to eliminate the "#ERROR" message by returning a zero if the HasData property returns a False.


REFERENCES

For more information about the HasData property, click Microsoft Access Help on the Help menu, type "HasData property" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words: pound error prb


Keywords          : kberrmsg kbdta RptSub 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 28, 1999