Update an Access linked table to use a UNC path

后端 未结 3 1567
自闭症患者
自闭症患者 2020-12-06 18:40

I have an Access 2010 database A.mdb with a list of tables, one of which is a linked table, linked from another Access database B.mdb on th

3条回答
  •  猫巷女王i
    2020-12-06 19:05

    Table links can be UNC paths. For example, say I have a linked table pointing to a database on \\192.168.1.2\Public\ which is mapped to drive P:. If I launch the VBA editor (Alt+F11), open the Immediate Window (Ctrl+G) and type...

    ?CurrentDB.TableDefs("remoteTable").Connect

    ...it will return...

    ;DATABASE=P:\B.accdb

    ...because I pointed to drive P: when I created the link.

    Now if I create and run the VBA function...

    Function linkToUnc()
    Dim cdb As DAO.Database
    Set cdb = CurrentDb
    cdb.TableDefs("remoteTable").Connect = ";DATABASE=\\192.168.1.2\Public\B.accdb"
    cdb.TableDefs("remoteTable").RefreshLink
    Set cdb = Nothing
    End Function
    

    ...the link is now a UNC path.

    By the way, you can create UNC links in the Linked Table Manager if you browse to "Network", "machine name", "share name", but that will give you the machine name (in my case \\PICO\Public\B.accdb).

提交回复
热议问题