I created a sub that accepts parameters to build the pivot table. I can call it like:
PivotFormat rst, "C_SNAME", "RowAxis", "CandidateInstanceID", "RowAxis", "ScaleTag", "ColumnAxis", "Score", "DataAxis"
I would like to make sure that no subtotals are displayed when the table is created. I can manually remove them by right clicking on the column/row and unselect subtotal once they are displayed but it is cumbersome and takes a long time when the pivot table is refreshed after the removal of the subtotal.
Could somebody tell me how to do that?
Thanks
SWK
Public Sub PivotFormat(rst As ADODB.Recordset, ParamArray avar() As Variant)
On Error GoTo HandleErr
Dim lngElements As Long
Dim i As Long
Dim fst1 As Object
i = 0
lngElements = UBound(avar()) 'This is total number of array elements - 1
DoCmd.OpenForm "PivotForm", acFormPivotTable
Set Forms!PivotForm.Recordset = rst
If Not (lngElements Mod 2) Then
With Forms!PivotForm.PivotTable.ActiveView
For i = 0 To (lngElements - 1) / 2
Set fst1 = .FieldSets(avar(2 * i))
Select Case (avar(2 * i + 1))
Case "RowAxis"
.RowAxis.InsertFieldSet fst1
Case "ColumnAxis"
.ColumnAxis.InsertFieldSet fst1
Case "DataAxis"
.DataAxis.InsertFieldSet fst1
Case "FilterAxis"
.FilterAxis.InsertFieldSet fst1
End Select
Next i
End With
With Forms!PivotForm.PivotTable
.ActiveView.ExpandDetails = Forms!PivotForm.PivotTable.Constants.plExpandAlways
End With
Else
MsgBox "Incorrect number of array elements"
End If
ExitHere:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Generic Pivot Format"
GoTo ExitHere
End Select
End Sub