+ Reply to Thread
Results 1 to 9 of 9

Pivot table with no data source - update pivotcache using disconnected recordset

  1. #1
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Pivot table with no data source - update pivotcache using disconnected recordset

    Is it possible to have a pivot table with neither a data table behind it or an Excel data connection....but instead update the pivotcache using an SQL statement run on the remote database, setting the pivotcache to the recordset like so:

    Please Login or Register  to view this content.
    The code above works fine until I remove the Excel data connection. I don't want a connection in the workbook, I don't want users to be able to refresh themselves, I just want to be able to update the pivotcache when the automated script runs.

    However, Excel won't let me. Pivot tables just whinge as soon as they don't have a permanent data source. Why? If I'm using a disconnected recordset as the data source....why do I need to have a permanent connection in Excel to the actual data source?
    Last edited by BellyGas; 03-30-2017 at 09:30 AM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    I believe it's because when you remove connection, it also removes data model used to create pivottable.

    I haven't done it myself, but you may be able to use .PivotCache.Create method to create temporary Pivot table on a new sheet.

    Then using PivotTable.CacheIndex property to assign temporary Pivot table's cache to replace existing one's.

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    Did a small test. You need PivotTable.ChangeConnection instead of .CacheIndex.
    https://msdn.microsoft.com/en-us/lib.../ff194492.aspx

    Unfortunately, doing so have removed all value fields from pivottables in my test. But then it could be due to some other factor.

    If I find anything more I'll let you know.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    Hi,

    That recordset is not disconnected as you have not cleared its connection. To the best of my recollection you should not have to refresh a pivotcache after assigning a recordset to it.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    The cnt.close part comes later in the macro. Does that not clear the connection?

  6. #6
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    According to MS, the .changeconnection command requires a 'WorkbookConnection', you can't use a recordset.

  7. #7
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    This is the code I've come up with for users to test whether an SQL statement they've just written is working:

    Please Login or Register  to view this content.
    Last edited by BellyGas; 04-03-2017 at 11:05 AM.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    Quote Originally Posted by BellyGas View Post
    The cnt.close part comes later in the macro. Does that not clear the connection?
    No, it doesn't. You need to set the recordset's connection property to Nothing.

  9. #9
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Pivot table with no data source - update pivotcache using disconnected recordset

    ahha! Ta, I'll let ya know how I get on.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pivot Table Auto Update Data Source?
    By Ket in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-20-2020, 02:05 PM
  2. Can I update data source from pivot table?
    By elbrujo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-02-2016, 10:25 PM
  3. using VBA to update a pivot table data source
    By bzl in forum Excel General
    Replies: 1
    Last Post: 06-03-2015, 04:38 PM
  4. Set Pivot Table source as ADO Recordset
    By bconner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2013, 12:52 PM
  5. Use ADO Recordset as source for Pivot table
    By bconner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-29-2012, 10:49 AM
  6. Update source data from pivot table
    By bryanbak3 in forum Excel General
    Replies: 0
    Last Post: 01-12-2012, 05:28 PM
  7. vba code to Update Pivot Table source data
    By ker9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2010, 04:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1