Manipulating backend linked tables

P

Piet Linden

Hi

How  can I rename or delete a linked table via code?

Many Thanks

Currentdb.Tabledefs("tablename").Delete

Or did you mean delete a backend table from the front end? In that
case,

DBEngine(0).OpenDatabase("PathToBackend")
DBEngine(0).TableDefs("TableName").Delete
 
D

Dirk Goldgar

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.
 

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