A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Ok - several things here
1: Do you need to create the pivot table every time or just refresh the data - if you just need to refresh then don't use PivotCaches.add
2: I know the array stuff comes out of the macro recorder but it is not needed at all and just makes the code harder to read
3: When adding a variable to a string you need to use a format such as: strSQL = "Base SQL String Goes Here " & Variable_Here & "Close string if necessary"
With all that in mind I would suggest that your code needs to be something along the lines of:
Dim strConn as string, strSQL as string
strConn = "ODBC;DSN=MS Access Database;DBQ=G:\BLA\BLA\TSS_TRACKING.mdb;DefaultDir=G:\BLAt\TSS;DriverId=25;FIL=MSAccess;MaxBufferSize=2048;PageTimeout=5;"
strSQL = "SELECT CALL_CENTER, U_NAME, TRANSFER, DWEEK, [COUNT] FROM G:\BLA\BLA\TSS_TRACKING.4_WEEK_TRACKING WHERE CALL_CENTER='" &filter_name & "'"
With thisworkbook
with .PivotCaches(1)
.SourceType:=xlExternal)
.Connection = strConn
.CommandType = xlCmdSql
.CommandText = strSQL
end with
with .pivottables(center_name)
.refreshtable
end with
End With
Rgds Geoff