Microsoft KB Archive/318096

= A Chart on a report displays the incorrect data in Access 2002 =

Article ID: 318096

Article Last Modified on 6/23/2005

-

APPLIES TO

 Microsoft Access 2002 Standard Edition, when used with:  Microsoft Windows 2000 Standard Edition

 Microsoft Windows XP Professional 

-



This article was previously published under Q318096





For a Microsoft Access 97 version of this article, see 317155.

For a Microsoft Access 2000 version of this article, see 318079.



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

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

<div class="symptoms_section">

SYMPTOMS
When you preview a report that contains a graph object, you might notice that the graph does not match the data that you expect. The graph may also reference data from a previous record in the report.

This behavior occurs only on computers that are running Microsoft Windows 2000 or Microsoft Windows XP.

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.

<div class="cause_section">

CAUSE
This behavior is caused by a timing problem between Microsoft Access and Microsoft Graph. The data is first transferred from Microsoft Access to Microsoft Graph. Microsoft Graph is responsible for generating the appropriate graph. If Microsoft Graph does not generate and return the graph object while Microsoft Access is formatting the report, the graph object might become disassociated from its recordset. This will cause the graph object to display an unrelated record.

<div class="resolution_section">

RESOLUTION
To work around this problem, use one of the following methods.

NOTE: These methods may not work in all situations.

Method 1: Requery the Graph Object
<ol> Open the report in Design view.</li> Click the section of the report that contains the graph object, and then click Properties on the View menu.</li> In the Properties dialog box, click the Events tab.</li> To the right of the On Format property box, click the Build (...) button, click the Code Builder, and then click OK.</li>  In the On Format event for the section, call the Requery action for the graph object. For example, if your graph object is named objMyGraph, you would type the following statement to requery the object: ' Replace objMyGraph with the name of your object. Me!objMyGraph.Requery </li></ol>

Method 2: Use a DoEvents Loop
<ol> Create a new module.</li>  Paste or type the following function into the new module: Function TestProc Dim i As Integer For i = 1 To 5 DoEvents Next i End Function Because this behavior is related to timing, you may have to increase the number of iterations through the loop. Because the number of iterations to be performed is variable (it is dependent on such things as the complexity of the report, the complexity of the graph, or the number of records), a maximum value is not provided. </li> Save and then close the module.</li> Open your report in Design view.</li> Open the Properties window for the section that contains the graph object, and then select the Events tab.</li> For the On Format event, call the TestProc procedure that you created in step 2.</li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Start Microsoft Access, and then create a new database.</li>  Create the following table: <pre class="fixed_text">  Table: Sheet1 Field Name: ID  Data Type: AutoNumber

Field Name: Field1 Data Type: Text Field Size: 255

Field Name: Field2 Data Type: Number Field Size: Double

Field Name: Field3 Data Type: Number Field Size: Double </li> Populate Sheet1 with the following sample data:

</li>  Create the following query: <pre class="fixed_text">  Query: qryTest --  Type: Select Query

Field: Field1 Field: Field2 Field: Field3 </li> In Design View, create a new report that is based on the qryTest query.</li> <li>Add Field2 and Field3 to the detail section of the report.</li> <li>On the Insert menu, click Chart, and then click anywhere in the detail section of the report. This starts the Chart Wizard. To add the data to the chart by using the Chart Wizard, follow these steps:

<ol style="list-style-type: lower-alpha;"> <li>Under View, click Queries.</li> <li>Click qryTest, and then click Next.</li> <li>In page 2 of the Chart Wizard, move Field2 and Field3 from the Available Fields box to the Fields for Chart box, and then click Next.</li> <li>In page 3 of the Chart Wizard, click Column Chart, and then click Next.</li> <li>Select Column Chart and click Next.</li> <li>Add Field3 to the Data node.</li> <li>Remove items from the Axis and Series nodes, and then click Next.</li> <li>Select Field2 for the Report Fields and Chart Fields lists.

NOTE: Click OK to the warning and set the fields as directed.</li> <li>Click Next, and then click Finish.</li></ol> </li> <li>Save and then close the report.</li></ol>

When the report is opened, it will display Field2, Field3, and the chart object. The chart should match the value of Field3. This is not true in all cases, because some charts will display the wrong record.

<div class="references_section">