Upfront, letting you know I might not have explained well or need to provide more code for context...
This question is using MS-Access to run vba to modify an excel sheet.
Found this code to refresh data in pivot at
It seems to work fine without error the first time I run it. Normally I only have to run the code once and only discovered the issue when doing some testing to adjust other things in the spreadsheet unrelated to the pivot, when I click the button to run the code a second time, it stops on this line with the error.
Run-time error 91 Object or variable with block not set
This code is only run one time per click and I finish it off by setting things to nothing.
If I completely close/exit MS-Access and reopen it. It is fine again to run once, but not more than once before the error happens.
This question is using MS-Access to run vba to modify an excel sheet.
Found this code to refresh data in pivot at
It seems to work fine without error the first time I run it. Normally I only have to run the code once and only discovered the issue when doing some testing to adjust other things in the spreadsheet unrelated to the pivot, when I click the button to run the code a second time, it stops on this line with the error.
Run-time error 91 Object or variable with block not set
Code:
Case "Submittal Data"
.Cells(2, 1).CopyFromRecordset rs
[highlight #FCE94F]For Each chPivot In ActiveWorkbook.PivotCaches[/highlight]
chPivot.Refresh
Next chPivot
.Range("H2:H" & lastRow + 1).ClearContents
End Select
This code is only run one time per click and I finish it off by setting things to nothing.
If I completely close/exit MS-Access and reopen it. It is fine again to run once, but not more than once before the error happens.