Change table name in linked table in Access

╄→гoц情女王★ 提交于 2019-12-11 11:20:20

问题


I'm trying to change the name of a table in Access. I've gone to the link manager and gone through that process. It will change to the Server I put it, but it never changes the Table name (Highlighted in yellow).


回答1:


It seems your goal is to change the linked TableDef's SourceTableName, but I doubt that is possible. Attempting to do it triggers error #3268:

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

So I think you will have to create a new linked TableDef with the Connect property from the old link and your new SourceTableName value and Append that to the TableDefs collection.

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


来源:https://stackoverflow.com/questions/35801628/change-table-name-in-linked-table-in-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!