Microsoft KB Archive/298046

= ACC2002: Setting Form RecordSource Property Resets PivotTable and PivotChart Views =

Article ID: 298046

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q298046



Advanced: Requires expert coding, interoperability, and multiuser skills.

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



SYMPTOMS
When you programmatically set the RecordSource or Recordset properties of a form, Microsoft Access clears the current PivotTable and PivotChart views of the form.



CAUSE
The Office Web Components are designed to reset whenever their data source changes.



RESOLUTION
If possible, do not set the RecordSource or Recordset properties of the form. If you need to filter the data that is being displayed in the PivotTable or PivotChart views, use the Office Web Components object model to filter the data as desired.

To do this, you can set the IncludedMembers or the ExcludedMembers properties (or both) of the appropriate Field object in the PivotTable object of the form. The following example demonstrates how to filter the PivotTable or PivotChart views of a form using the Office Web Components object model.

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. CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Open the sample database Northwind.mdb. Create a new, blank form in Design view. In the Database window, drag the Sales Analysis Subform2 form onto the new form to create a subform.  Add a command button to the main form, and then set the following properties:   Command button --  Name: cmdFilterPivotChart Caption: Filter PivotChart  On the View menu, click Code to view the module of the form.</li> On the Tools menu, click References.</li> Click Browse.</li> Browse to and select the C:\Program Files\Common Files\Microsoft Shared\Web Components\10\OWC10.DLL file, and then click Open.</li> Click OK to close the References dialog box.</li>  Add the following Visual Basic for Applications code to the Click event of the command button: Private Sub cmdFilterPivotChart_Click Dim pTable As OWC10.PivotTable Dim pFieldset As OWC10.PivotFieldSet Dim pField As OWC10.PivotField Set pTable = Me.Controls(&quot;PivotChart&quot;).Form.PivotTable Set pFieldset = pTable.ActiveView.FieldSets(&quot;LastName&quot;) Set pField = pFieldset.Fields(&quot;LastName&quot;) pField.IncludedMembers = Array(&quot;Davolio&quot;, &quot;King&quot;, &quot;Callahan&quot;) 'Alternatively, you could set the ExcludedMembers property 'if you wished to exclude certain values 'pField.ExcludedMembers = Array(&quot;Davolio&quot;, &quot;King&quot;, &quot;Callahan&quot;) End Sub </li> On the File menu, click Close and Return to Microsoft Access.</li> On the File menu, click Save. When you are prompted, save the form as frmMain .</li> On the View menu, click Form View. Note that the subform appears in PivotChart view and is charting data for all employees.</li> Click the command button.</li></ol>

Note that the PivotChart view is filtered to show only data for employees Davolio, King, and Callahan.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
Any time that the data source changes for the PivotTable or PivotChart object, it automatically resets and clears all drop zones. This is done to prevent errors from showing when the fields on the PivotTable or PivotChart object do not exist in the new data source.

Steps to Reproduce the Behavior
<ol> CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

</li> Open the sample database Northwind.mdb.</li> Open the Sales Analysis Subform2 form in PivotChart view. Note that the form contains a custom PivotChart object with fields on the Category, Series, Data, and Filter axes.</li> Press CTRL+G to view the Immediate window in the Visual Basic Editor.</li>  Type the following in the Immediate window, and then press ENTER.

NOTE: The following command will clear the PivotChart and PivotTable views of the Sales Analysis Subform2 form, and cannot be undone. You may want to make a backup copy of this form before proceeding. Forms(&quot;Sales Analysis Subform2&quot;).RecordSource = &quot;SELECT * FROM Orders&quot; </li> On the File menu, click Close and Return to Microsoft Access.</li></ol>

Note that the Sales Analysis Subform2 PivotChart object has been reset to a blank PivotChart object.

Additional query words: prb pivot chart table

Keywords: kbprb KB298046

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.