John said:
How can I rename or delete a linked table via code?
Are you wanting to rename or delete the linked table in the front-end, which
is simple, or in the back-end, which is a bit more complicated.
In the front-end (not affecting the table in the back-end):
' Delete linked table (just the link):
DoCmd.DeleteObject acTable, "LinkedTableName"
' Rename linked table (just the link):
DoCmd.Rename "NewNameForTable", acTable, "OldTableName"
In the back-end (breaking any front-end links to the table in the
front-end):
Dim strBEName As String
Dim dbBE As DAO.Database
' Get back-end name from linked table's Connect property.
' NOTE: Only works for linked Jet tables.
strBEName = _
Mid(CurrentDb.TableDefs("LinkedTableName").Connect, 11)
' Open a Database object on the the back-end database.
Set dbBE = DBEngine.OpenDatabase( strBEName)
' Delete table in back-end.
dbBE.TableDefs.Delete "TableNameToDelete"
' Rename table in back-end:
dbBE.TableDefs("OldTableName").Name = "NewNameForTable"
All of the above example code would be executed from the front-end.