ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   PivotTable and connection string (https://www.excelbanter.com/excel-programming/281577-pivottable-connection-string.html)

lc

PivotTable and connection string
 

Sorry about the report (really not my habit) but my original post since
yesterday went all the way down....


With Excel 2003, I'm trying to replace connection string and make query
dynamic but am getting "strange" errors. This is what I have:

Private Sub refreshData(dFrom As Date, dTo As Date)
Dim pt As PivotTable
Dim pc As PivotCache

Set pt = Sheet1.PivotTables(1)
Set pc = ActiveWorkbook.PivotCaches(pt.CacheIndex)

pc.Connection = "SQLOLEDB.1;User ID=sa;Initial Catalog=QuantumPlan;Data
Source=myServer"
pc.CommandText = "select .... '"

pt.PivotCache.Refresh
End Sub

I'm getting 1004 error on pc.Connection line. Anyone has any idea why and
how to get around it?

Thanks a lot.

lc




Tom Ogilvy

PivotTable and connection string
 
It is highly probable that your connection string is flawed.

--
Regards,
Tom Ogilvy

"lc" wrote in message
...

Sorry about the report (really not my habit) but my original post since
yesterday went all the way down....


With Excel 2003, I'm trying to replace connection string and make query
dynamic but am getting "strange" errors. This is what I have:

Private Sub refreshData(dFrom As Date, dTo As Date)
Dim pt As PivotTable
Dim pc As PivotCache

Set pt = Sheet1.PivotTables(1)
Set pc = ActiveWorkbook.PivotCaches(pt.CacheIndex)

pc.Connection = "SQLOLEDB.1;User ID=sa;Initial

Catalog=QuantumPlan;Data
Source=myServer"
pc.CommandText = "select .... '"

pt.PivotCache.Refresh
End Sub

I'm getting 1004 error on pc.Connection line. Anyone has any idea why and
how to get around it?

Thanks a lot.

lc







All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com