Linked table properties (in VBA)

Gates Is Antichrist

Well-known Member
Joined
Aug 15, 2002
Messages
1,961
I wish to change what a linked table refers to in code. I figured it would be something like

Sub foo(sWhoToPointTo as String)
Dim db As Database, rs As Recordset, tdf As TableDef

Set db = CurrentDb
Set tdf = db.OpenRecordset("LinkAlias") 'I gather that it's dbOpenDynaset type

'need I also dynaset the "linkee" sWhoToPointTo now?
'And what now? Here is where I want to "re-link." I also want it to be permanent.

Set tdf = Nothing
Set db = Nothing
End Sub

TIA
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This is not something I have played with but look up "RefreshLink Method" in help. The example code from there covers what you need I think.

Peter
 
Upvote 0
Good job - that's really very close to what I need (if it even turns out to be possible in code). I can't quite implement it because I'm using a recordset instead of tabledef. Piddling around I had no luck setting Source or Connect and bad luck even displaying them.

I hope someone who knows something about recordsets and tabledefs sees this, but thanks still for your fine shooting in unfamiliar territory.

Private Sub foo(sWhoToPointTo as string)
Dim rs As Recordset, tdf As TableDef

Set rs = CurrentDb.OpenRecordset("LinkAlias") 'I gather that it's dbOpenDynaset type
'rs.Source = "BOB" 'fraid not
'debug.print tdf.Connect 'Do I want to use Tabledef?

'need I also dynaset the "linkee" sWhoToPointTo now?
'And what now? Here is where I want to "re-link." I also want it to be permanent.

Set rs = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,567
Messages
6,160,540
Members
451,655
Latest member
rugubara

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