Consulting

Results 1 to 5 of 5

Thread: Data Source validation

  1. #1
    VBAX Regular
    Joined
    May 2004
    Location
    Houston, Texas
    Posts
    6
    Location

    Question Data Source validation

    I have a spreadsheet with 14 (or so) tabs that contain pivot tables from MSAccess database.
    I need to make certain that these are all pulling data from the same database, hopefully without rebuilding them. The only way that I have found to determine the datasource is to go into each tab, into the Pivot Table wizard and view the SQL to determine the path and file name of the source data.
    Is there any other way to determine what datasources are being used? Is it possible to do this for the entire document instead of each tab?
    If you find a path with no obstacles, it probably doesn't lead anywhere.

  2. #2
    VBAX Regular
    Joined
    Jun 2004
    Location
    Denmark
    Posts
    58
    Location
    Hi TMacorke

    If your pivottables all are directly from access datases you could try the following code.


    Sub GetPivotConnection()
    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim pc As PivotCache
    Dim temp As Variant
    Dim msg As String
    'go through each worksheet in the active workbook
    For Each ws In ActiveWorkbook.Worksheets
    'for each pivottable, get the pivotcache's connectionstring
    For Each pt In ws.PivotTables
    'take the databasestring out of the connectionstring
    temp = Split(pt.PivotCache.Connection, ";")
    msg = msg & ws.Name & "---" & pt.Name & "---" & temp(2) & vbCrLf
    Next
    Next
    'display the worksheets, pivottables and their databases
    MsgBox msg
    End Sub

    BR
    Tommy Bak

  3. #3
    VBAX Regular
    Joined
    May 2004
    Location
    Houston, Texas
    Posts
    6
    Location
    THANK YOU!
    That works GREAT....for the first 11 pivot table data sources...but stops there.
    There are 7 more pivot tables in this file....?
    If you find a path with no obstacles, it probably doesn't lead anywhere.

  4. #4
    VBAX Regular
    Joined
    Jun 2004
    Location
    Denmark
    Posts
    58
    Location
    Ok, I think you reached the max. number of characters i a messagebox.
    This one makes a new sheet and places the information there.

    Sub GetPivotConnection()
        Dim ws As Worksheet
        Dim wsNew As Worksheet
        Dim pt As PivotTable
        Dim pc As PivotCache
        Dim vtemp As Variant
        Dim lCnt As Long
    'add a new worksheet
        On Error Resume Next
        Set wsNew = Worksheets("Connectionstrings")
        If Not wsNew Is Nothing Then
            wsNew.Cells.ClearContents
        Else
            Set wsNew = Worksheets.Add
            wsNew.Name = "Connectionstrings"
        End If
        On Error GoTo 0
    'set header
        wsNew.Range("A1:C1") = Array("Worksheet", "Pivot name", "Connection")
        wsNew.Range("A1:C1").Font.Bold = True
         'loop through each worksheet in the active workbook
        For Each ws In ActiveWorkbook.Worksheets
             'for each pivottable, get the pivotcache's connectionstring
            For Each pt In ws.PivotTables
                 'take the databasestring out of the connectionstring
                vtemp = Split(pt.PivotCache.Connection, ";")
                 'display the worksheets, pivottables and their databases in new worksheet
                lCnt = lCnt + 1
                wsNew.Range("A1:C1").Offset(lCnt, 0) = Array(ws.Name, pt.Name, vtemp(2))
            Next
        Next
        wsNew.Columns("A:C").AutoFit
    End Sub


    BR
    Tommy Bak

  5. #5
    VBAX Regular
    Joined
    May 2004
    Location
    Houston, Texas
    Posts
    6
    Location
    THAT IS WONDERFUL!!
    Thank you so very much!!
    If you find a path with no obstacles, it probably doesn't lead anywhere.

Posting Permissions

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