Modifying pivottable command text creates new data source?

BJE1

New Member
Joined
Mar 24, 2010
Messages
4
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?

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
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top