在 Access 中更改链接 table 中的 table 名称

Change table name in linked table in Access

我正在尝试更改 Access 中 table 的名称。我已经去找 link 经理并完成了那个过程。它会更改为我放置的服务器,但它永远不会更改 Table 名称(以黄色突出显示)。

您的目标似乎是更改 linked TableDefSourceTableName,但我怀疑这是否可能。尝试这样做会触发错误 #3268:

Cannot set this property once the object is part of a collection.

所以我认为您必须使用旧 link 中的 Connect 属性 和您的新 SourceTableName 值和 AppendTableDefs 集合。

Const cstrOldName As String = "dbo_tblFoo2"
Dim db As DAO.Database
Dim tdfOld As DAO.TableDef
Dim tdfNew As DAO.TableDef
Set db = CurrentDb
Set tdfOld = db.TableDefs(cstrOldName)
tdfOld.Name = cstrOldName & "_old" ' rename the old link

Set tdfNew = db.CreateTableDef
With tdfNew
    .Name = cstrOldName
    .Connect = tdfOld.Connect
    .SourceTableName = "dbo.Dual"
End With
db.TableDefs.Append tdfNew