Hi,
I am getting an error "Application-defined or object-defined error : 1004" on the highlighted line below.
Private Sub CommandButton1_Click()
Dim PvtCache As PivotCache
Dim AppAccess As Access.Application
Dim dbRecordset As Variant
On Error GoTo errl
Set AppAccess = CreateObject("Access.Application")
AppAccess.OpenCurrentDatabase Sheet32.Cells(14, 3)
Set dbRecordset = AppAccess.CurrentDb.OpenRecordset _
("_FSTEP_BULK_HSFS_REVENUE")
Set PvtCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlExternal)
Set PvtCache.Recordset = dbRecordset
With PvtCache
.CreatePivotTable TableDestination:=Range("A43"), _
TableName:="Performance"
End With
With ActiveSheet.PivotTables("Performance")
.SmallGrid = False
With .PivotFields("C_4")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("C_2")
.Orientation = xlColumnField
.Position = 1
End With
With .PivotFields("C_7")
.Orientation = xlDataField
.Position = 1
End With
End With
Exit Sub
errl:
MsgBox Err.Number & " " & Err.Description
AppAccess.CloseCurrentDatabase
Set AppAccess = Nothing
Set dbRecordset = Nothing
Set PvtCache = Nothing
End Sub
I cannot use ADODB or DAO because I am on Win 64-bit machine. But it should still work I assume so what is it that I am doing wrong here?
Bookmarks