I have an Access application where i create an excel worksheet from an Access database and then need to create an excel pivot table. The following code successfully creates the workbook and populates a sheet with the query. But when I try to create the pivot table I get the following error: "Object doesn't support this property or method"
My guess is that I'm not fully qualifying some objects - but if so, I don't know the syntax.
Here is the code:
Appreciate any help.
My guess is that I'm not fully qualifying some objects - but if so, I don't know the syntax.
Here is the code:
Code:
Dim db As Database
Dim rs As DAO.Recordset
Dim xlWB As Object
Dim xlWS As Object
Dim xlRng As Object ' define a range name
'open workbook
Set xlWB = xlApp.Workbooks.Open(sDestinationFile)
Set xlWS = xlWB.Worksheets("Data")
Set rs = db.OpenRecordset("qryCondensed_Assumed", dbOpenSnapshot)
Set xlRng = xlWS.Range("StartReport") 'the starting location for the report on the spreadsheet
'copy Access recordset to range in a worksheet.
xlRng.CopyFromRecordset rs
'create pivot table *** PROBLEM HERE ***
xlWB.ActiveWorkbook.PivotCaches.Add _
(SourceType:=1, SourceData:="Data!R1C1:R3390C38").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion:=10
Appreciate any help.