Updating Configure Refresh Path Programmatically

Started by penguin76, October 28, 2011, 09:08:13 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

penguin76

Hi,

I have a visio 2010 file with lots of linked data to an Access database.  There are multiple datarecordsets (External data tabs) with their own unique CommandStrings (queries).  The problem I'm running into is reconfiguring each of these linked data tables when I change the name or location of the linked database.  So I have the below script to go through and update all of the "DataConnection.ConnectionString" parameters, and then I refresh the datarecordset.

So this all seems to working just fine, and I can see the new data reflected in the tables from my new database, however, when I then right click and select "Configure Refresh" > "Change Data Source" > "(Next)" the string that shows up in this dialog box still points to the old database.  I'm having a hard time figuring out how to get this link to update with the new linked database.  Any ideas? (See attached image). 

Thanks for the help,

Sub swapDataRecordSets()
   
    'Enable diagram services
    Dim vsoDataRecordset As Visio.DataRecordset
    Dim DiagramServices As Integer
   
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140

    'new database path
    newDatabaseName = "C:\MyDir\Simulation Demo Master.mdb"
   
    ' Generate new connection string
    strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" _
                   & "User ID=Admin;" _
                   & "Data Source=" + newDatabaseName + ";" _
                   & "Mode=Read;" _
                   & "Extended Properties="""";" _
                   & "Jet OLEDB:System database="""";" _
                   & "Jet OLEDB:Registry Path="""";" _
                   & "Jet OLEDB:Engine Type=5;" _
                   & "Jet OLEDB:Database Locking Mode=0;" _
                   & "Jet OLEDB:Global Partial Bulk Ops=2;" _
                   & "Jet OLEDB:Global Bulk Transactions=1;" _
                   & "Jet OLEDB:Create System Database=False;" _
                   & "Jet OLEDB:Encrypt Database=False;" _
                   & "Jet OLEDB:Don't Copy Locale on Compact=False;" _
                   & "Jet OLEDB:Compact Without Replica Repair=False;" _
                   & "Jet OLEDB:SFP=False;" _
                   & "Jet OLEDB:Support Complex Data=False"


    nTabs = Application.ActiveDocument.DataRecordsets.Count
    For iTab = 1 To nTabs
        Set vsoDataRecordset = Application.ActiveDocument.DataRecordsets(iTab)
        With Application.ActiveDocument.DataRecordsets(iTab)
            .DataConnection.ConnectionString = strConnection
           
        End With
        vsoDataRecordset.Refresh
    Next iTab
   
    'Refresh datarecordsets


End Sub

aledlund

for that I'd probably suggest that you investigate .ODC files. On my system they are stored in
c:\Users\'username'\My Documents\My Data Sources\
These are XML files (text editor) that are used to store Office Data Connection information.
hth,
Al