ACC2002: Setting Form RecordSource Property Resets PivotTable and PivotChart Views (298046)
The information in this article applies to:
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.
- On the Tools menu, click References.
- Click Browse.
- Browse to and select the C:\Program Files\Common Files\Microsoft Shared\Web Components\10\OWC10.DLL file, and then click Open.
- Click OK to close the References dialog box.
- 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("PivotChart").Form.PivotTable
Set pFieldset = pTable.ActiveView.FieldSets("LastName")
Set pField = pFieldset.Fields("LastName")
pField.IncludedMembers = Array("Davolio", "King", "Callahan")
'Alternatively, you could set the ExcludedMembers property
'if you wished to exclude certain values
'pField.ExcludedMembers = Array("Davolio", "King", "Callahan")
End Sub
- On the File menu, click Close and Return to Microsoft Access.
- On the File menu, click Save. When you are prompted, save the form as frmMain.
- On the View menu, click Form View. Note that the subform appears in PivotChart view and is charting data for all employees.
- Click the command button.
Note that the PivotChart view is filtered to show only data for employees Davolio, King, and Callahan.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 6/23/2005 |
---|
Keywords: | kbprb KB298046 |
---|
|