PC Review


Reply
Thread Tools Rate Thread

Can't set CommandText if pivot table copied

 
 
steveh
Guest
Posts: n/a
 
      26th Jan 2007
I have a pivot table on sheet1 that I can change the query parameters
using the PivotCache.CommandText property. But if I copy that pivot
table onto a new worksheet, or copy the entire worksheet, I can no
longer set the PivotCache.CommandText for either pivot tables. If I
delete the copied worksheet, I can set the CommandText again on the
original pivot table.

Does anyone have any solutions?

Thanks for looking.
 
Reply With Quote
 
 
 
 
Debra Dalgleish
Guest
Posts: n/a
 
      26th Jan 2007
If it's an ODBC connection, you can temporarily change it to OLEDB, then
change the command text. For example:

'==============
Sub SetCmdText()
Dim pc As PivotCache
Dim strConn As String
Dim strConn2 As String
Set pc = ActiveWorkbook.PivotCaches(1)
strConn = pc.Connection
strConn2 = Replace(strConn, "ODBC", "OLEDB")

pc.Connection = strConn2
pc.CommandText _
= ActiveSheet.Range("rngCmdTxt2").Value
pc.Connection = strConn
ActiveWorkbook.RefreshAll

End Sub
'=================

steveh wrote:
> I have a pivot table on sheet1 that I can change the query parameters
> using the PivotCache.CommandText property. But if I copy that pivot
> table onto a new worksheet, or copy the entire worksheet, I can no
> longer set the PivotCache.CommandText for either pivot tables. If I
> delete the copied worksheet, I can set the CommandText again on the
> original pivot table.
>
> Does anyone have any solutions?
>
> Thanks for looking.



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

 
Reply With Quote
 
steveh
Guest
Posts: n/a
 
      27th Jan 2007
I must be doing something wrong because that didn't work for me.


Debra Dalgleish wrote:
> If it's an ODBC connection, you can temporarily change it to OLEDB, then
> change the command text. For example:
>
> '==============
> Sub SetCmdText()
> Dim pc As PivotCache
> Dim strConn As String
> Dim strConn2 As String
> Set pc = ActiveWorkbook.PivotCaches(1)
> strConn = pc.Connection
> strConn2 = Replace(strConn, "ODBC", "OLEDB")
>
> pc.Connection = strConn2
> pc.CommandText _
> = ActiveSheet.Range("rngCmdTxt2").Value
> pc.Connection = strConn
> ActiveWorkbook.RefreshAll
>
> End Sub
> '=================
>
> steveh wrote:
>> I have a pivot table on sheet1 that I can change the query parameters
>> using the PivotCache.CommandText property. But if I copy that pivot
>> table onto a new worksheet, or copy the entire worksheet, I can no
>> longer set the PivotCache.CommandText for either pivot tables. If I
>> delete the copied worksheet, I can set the CommandText again on the
>> original pivot table.
>>
>> Does anyone have any solutions?
>>
>> Thanks for looking.

>
>

 
Reply With Quote
 
Debra Dalgleish
Guest
Posts: n/a
 
      27th Jan 2007
Ron Coderre has a pivot table add-in that lets you view and edit a pivot
table's connection string and command text, in Excel 2002 or Excel 2003:

http://www.contextures.com/xlPivotPlay01.html

Maybe that will help.

steveh wrote:
> I must be doing something wrong because that didn't work for me.
>
>
> Debra Dalgleish wrote:
>
>> If it's an ODBC connection, you can temporarily change it to OLEDB,
>> then change the command text. For example:
>>
>> '==============
>> Sub SetCmdText()
>> Dim pc As PivotCache
>> Dim strConn As String
>> Dim strConn2 As String
>> Set pc = ActiveWorkbook.PivotCaches(1)
>> strConn = pc.Connection
>> strConn2 = Replace(strConn, "ODBC", "OLEDB")
>>
>> pc.Connection = strConn2
>> pc.CommandText _
>> = ActiveSheet.Range("rngCmdTxt2").Value
>> pc.Connection = strConn
>> ActiveWorkbook.RefreshAll
>>
>> End Sub
>> '=================
>>
>> steveh wrote:
>>
>>> I have a pivot table on sheet1 that I can change the query parameters
>>> using the PivotCache.CommandText property. But if I copy that pivot
>>> table onto a new worksheet, or copy the entire worksheet, I can no
>>> longer set the PivotCache.CommandText for either pivot tables. If I
>>> delete the copied worksheet, I can set the CommandText again on the
>>> original pivot table.
>>>
>>> Does anyone have any solutions?
>>>
>>> Thanks for looking.

>>
>>
>>



--
Debra Dalgleish
Contextures
http://www.contextures.com/tiptech.html

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot cache when pivot table copied =?Utf-8?B?TWljaGFlbCBHbGVubg==?= Microsoft Excel Programming 1 31st Oct 2007 05:38 PM
How can I manage pivot table macros? Copied sources isn't safe =?Utf-8?B?dGFzY2lt?= Microsoft Excel Crashes 0 21st Jul 2006 12:34 PM
pivot table Commandtext causes runtime error 1004 in excel 2000 =?Utf-8?B?VGhlcmV6ZWU=?= Microsoft Excel Programming 0 12th Apr 2006 04:39 AM
Why did Pivot table charts copied into workbook with standard cha. =?Utf-8?B?VGFtYUpv?= Microsoft Excel Charting 1 26th Oct 2004 01:53 AM
Can Pivot Table layout be copied??? K. Georgiadis Microsoft Excel Misc 1 1st Sep 2004 01:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:54 AM.