I create a pivot table. The PivotCache and the Class1 combobox are filled with values but the RowField section is empty. What's wrong with my code?
Set Cn = New ADODB.Connection
ConnStr = "Provider=SQLOLEDB.1;Password=1;Persist Security Info=True;User ID=User1;Initial Catalog=NepokorenkaSQL;Data Source=Server1"
Cn.Open ConnStr
Dim rst_Reestr As New ADODB.Recordset
sqlstr = "SELECT Class1 FROM Class"
Set rst_Reestr = Cn.Execute(sqlstr)
Set objPivotCache = ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlExternal)
Set objPivotCache.Recordset = rst_Reestr
With objPivotCache
.CreatePivotTable TableDestination:=Range("A3"), _
TableName:="Performance"
End With
With ActiveSheet.PivotTables("Performance").PivotFields("Class1")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("Performance").PivotFields("Class1").Subtotals = _
Array(False, False, False, False, False, False, False, False, False, False, False, False)
Bookmarks