Hi,

A question; I've created a pivottable and cache based on a access query in code, in stead of using the pivottable wizard. then I wrote some code to update the tables (charts). Purpose is to create a very transportable db and worksheets, now I only have to alter one connectionstring.
But, here's the problem, when I update the pivottables, the database stays locked. After opening all the other recordsets, the db unlocks, but using this code it stays locked

If someone can help me out, thanks

in class:
Dim RS As New ADODB.Recordset
Public StrCN As String

Public Sub PvtCacheUpdate(ByRef WsCodeName As Worksheet, ByRef PvtTableName As String, _
ByRef ConnString As String, ByRef StoredProcedure As String)
Dim PC As PivotCache
Dim PT As PivotTable
On Error GoTo catch
Set RS = New ADODB.Recordset
Set PT = WsCodeName.PivotTables(PvtTableName)
Set PC = PT.PivotCache
PC.MaintainConnection = False
StrCN = ConnString

Call RS.Open("[" & StoredProcedure & "]", StrCN, adOpenForwardOnly, adLockReadOnly, adCmdTable)
Set PC.Recordset = RS
PT.RefreshTable
catch:
If RS.State = ObjectStateEnum.adStateOpen Then RS.Close
Set RS = Nothing
Set PC = Nothing
Set PT = Nothing
End Sub