Change one table link by vba

K

K

Hi all, I got macro below which changes the link of all linked tables
in access. How can I ammend it to change only one table link with the
name "Summary". Please can any friend can help

Public Sub RelinkTables()
Dim Dbs As Database
Dim Tdf As TableDef
Dim Tdfs As TableDefs
Set Dbs = CurrentDb
Set Tdfs = Dbs.TableDefs
'Loop through the tables collection
For Each Tdf In Tdfs
If Tdf.SourceTableName <> "" Then 'If the table source is other than a
base table
Tdf.Connect = ";DATABASE=\\Home\Document\Record.mdb"
Tdf.RefreshLink 'Refresh the link
End If
Next 'Goto next table
End Sub
 
S

Stefan Hoffmann

hi,

Hi all, I got macro below which changes the link of all linked tables
in access. How can I ammend it to change only one table link with the
name "Summary".
Instead of the loop request that table from the TableDefs collection.

Public Sub RelinkSummaryTable()

'On Local Error Resume Next

Dim db As DAO.Database
Dim tdf As DAO.TableDef

Set db = CurrentDb
Set tdf = db.TableDefs.Item("Summary")
tdf.Connect = ";DATABASE=\\Home\Document\Record.mdb"
tdf.RefreshLink
Set tdf = Nothing
Set db = Nothing

End Sub



mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top