I have a pivottable linked to an odbc external data source. When I run a VBA script that updates the date used in the data source connection query called "deductions", a new connection called "Connection" is created. Reviewing the commandtext of "deductions" shows it is unchanged and the new "connection" has the revised date.
The VBA script seems good because it works fine if the data is going into a regular table instead - no new connections are created and the data in the table is as expected.
I tried changing the VBA to update the pivotcache.commandtext instead of the connection.commandtext but had the same result. Thoughts?
The VBA script seems good because it works fine if the data is going into a regular table instead - no new connections are created and the data in the table is as expected.
I tried changing the VBA to update the pivotcache.commandtext instead of the connection.commandtext but had the same result. Thoughts?
Code:
PPD = Format(Sheets("WORKSHEET").Range("B4"), "yyyy-mm-dd")
ActiveWorkbook.Connections("DEDUCTIONS").ODBCConnection.CommandText = Array( _
"SELECT HISDED.PR_DED_EMP_NO, HISDED.PR_DED_PAY_PRD_DAT, HISDED.PR_DED_COD, HISDED.PR_DED_AMT" & Chr(13) & "" & Chr(10) & "FROM HISDED HISDED" & Chr(13) & "" & Chr(10) & "W" _
, _
"HERE (HISDED.PR_DED_PAY_PRD_DAT={ts '" & PPD & "'}) AND (HISDED.PR_DED_COD='401') OR (HISDED.PR_DED_" _
, _
"PAY_PRD_DAT={ts '" & PPD & "'}) AND (HISDED.PR_DED_COD='40P') OR (HISDED.PR_DED_PAY_PRD_DAT={ts '" & PPD & "'})", _
"AND (HISDED.PR_DED_COD='4CD') OR (HISDED.PR_DED_PAY_PRD_DAT={ts '" & PPD & "'}) AND (HISDED.PR_DED_COD='LON')")
ActiveWorkbook.Connections("Deductions").Refresh