Microsoft KB Archive/301582

= PRB: Incorrect ChildMembers.Count for PivotMember Object =

Article ID: 301582

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Office Web Components

-



This article was previously published under Q301582



SYMPTOMS
When you use the ChildMembers property of a PivotMember object to retrieve a collection of child members, the child members collection is empty and the Count property returns zero.



CAUSE
When you retrieve a PivotMember object by calling one of the following methods or properties, the PivotMember object that is returned may be &quot;cloned&quot;:
 * FindMember method
 * IncludedMembers property
 * ExcludedMembers property
 * OrderedMembers property

Cloned members are disconnected; due to the manner in which the PivotTable component internally handles disconnected members, you may be unable to retrieve the ChildMembers collection for a cloned member. Likewise, if you retrieve the ParentMember for a cloned PivotMember, you may also be unable to retrieve the ChildMembers for that ParentMember.



RESOLUTION
To work around this problem, obtain a reference to the PivotMember by calling the FindMember method using the path for that member. This workaround is illustrated in the More Information section.



MORE INFORMATION
  Paste the following code in any text or HTML editor: 



#1  #2  





Dim c     'For PivotTable constants Dim oView

Function Window_OnLoad

PTable.AutoFit = True Set c = PTable.Constants

'Connect to the data source. PTable.ConnectionString = _ &quot;provider=msolap;data source=YourServer;inital catalog=Foodmart 2000;&quot; PTable.DataMember = &quot;Sales&quot;

Set oView = PTable.ActiveView

'Add Dimensions to the column and filter axes. oView.ColumnAxis.InsertFieldSet oView.FieldSets(&quot;Time&quot;) oView.ColumnAxis.FieldSets(&quot;Time&quot;).Fields(&quot;Year&quot;).Expanded = True oView.RowAxis.InsertFieldSet oView.FieldSets(&quot;Store&quot;) oView.RowAxis.FieldSets(&quot;Store&quot;).Fields(&quot;Store Country&quot;).Expanded = True 'Add a total to the data area. oView.DataAxis.InsertTotal oView.Totals(&quot;Store Sales&quot;) oView.Totals(&quot;Store Sales&quot;).NumberFormat = &quot;_($* #,##0_)&quot;

End Function Function MyButton1_OnClick

Dim oPM, oPM2 Set oPM = oView.FieldSets(&quot;Store&quot;).Member.ChildMembers(&quot;USA&quot;) Set oPM2 = oView.FieldSets(&quot;Store&quot;).FindMember(oPM.UniqueName) MsgBox &quot;There are &quot; & oPM2.ChildMembers.Count & &quot; Child Members in &quot; _ & oPM2.UniqueName End Function

Function MyButton2_OnClick

Dim oPM, oPM2 'The next line returns the member [Store].[All Stores].[USA] Set oPM = oView.FieldSets(&quot;Store&quot;).Member.ChildMembers(&quot;USA&quot;) Set oPM2 = oView.FieldSets(&quot;Store&quot;).FindMember( _           oPM.Path(c.plFindFormatPathName), c.plFindFormatPathName) MsgBox &quot;There are &quot; & oPM2.ChildMembers.Count & &quot; Child Members in &quot; _ & oPM2.UniqueName End Function </SCRIPT> </HTML> </li> <li>In the connection string for the PivotTable, replace &quot;YourServer&quot; with the name of an Analysis Server that contains the Foodmart 2000 sample database.</li> <li>Save the file as C:\Test.htm.</li> <li>Start Internet Explorer and browse to C:\Test.htm.</li> <li>After the Web page is rendered and the PivotTable is loaded with data, click #1. A message box displays and indicates an incorrect number of child members for [Store].[All Stores].[USA]. Click OK to dismiss the message box.</li> <li>Click #2. A message box displays and indicates the correct number of child members for [Store].[All Stores].[USA]. Click OK to dismiss the message box.</li></ol>

<div class="references_section">