Change connection string of linked table

RichardMGreen

Well-known Member
Joined
Feb 20, 2006
Messages
2,177
Hi all

I want to change the filepath of a linked table in VBA.
So far I've got this:-
Code:
Sub test()
    Dim tbl As TableDef
    For Each tbl In TableDefs
        If Len(tbl.Connect) > 0 Then
            
    
End Sub

As far as I can make out, checking the Connect property tells me if it's a linked table, but I'm not sure how to change just the path part.

Can someone point me in the right direction please?

::edit::
I also found this code which will change the entire string:-
td.Connect = "MS Access;Database=C:\MyBackEnd.mdb;"
td.RefreshLink
(this is changing a table linked to another Access file but I'm linking to CSV files)
but do I need to do a refreshlink for each table individually or can I do them all at once at the end of the loop?
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
OK, I'm making a bit of progress.
I've got the connection string for one of the files which is:-
Text;DSN=ASMT Link Specification2;FMT=Delimited;HDR=NO;IMEX=2;CharacterSet=850;DATABASE=H:\Data\Databases\extract

and it's this bit:-
H:\Data\Databases\extract

I want to change.

It looks like the rest of it stays the same apart from the DSN section.

How can update just the filepath within the string?
 
Upvote 0

Forum statistics

Threads
1,224,588
Messages
6,179,743
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top