Modify linked SQL table name in Access 2013

2019-09-17 16:45发布

问题:

I have a SQL table linked in Access. I'd like to know how to change the linked table object to reference a different table with the same design but another name. For example, I link Table1 and create forms with it, and now need to change it to Table2.

There doesn't seem to be an easy way to do this.

  • The table Description in Design View contains all the linked database and table information but it's not editable.
  • Using the Linked Table Manager, I can change the database the table comes from, but the tables in both databases need to have the same name.
  • I can create a query with Select * From Table1 and change it to Select * From Table2 to switch tables, but I don't want to use a workaround if I don't have to.

回答1:

Remove the linked table, and use DoCmd.TransferDatabase to recreate the link with different names:

DoCmd.TransferDatabase acLink, "ODBC", your_ODBC_String, acTable, _
    "schema.source_table", "target_table"

You can look up your_ODBC_String from existing linked tables.

Add the StoreLogin:=True parameter if needed.