ms-access如何在保持格式的同时更新链接表路径

6ljaweal  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(313)

在access中,我从.csv文件中获取了大约20个链接表,第一行用作表头。但是,每次更新源路径时,我似乎都无法保留头文件,所以每次都必须手动删除并重新链接它们,这很痛苦。知道在源路径更改后如何保持表格式和属性吗?

nkkqxpd9

nkkqxpd91#

可以使用vba修改链接。示例代码:

Dim td As TableDef
Dim db As DAO.Database
Dim strOld As String
Dim strNew As String
'replace the following strings as needed
strOld = "C:\Users\June\Forums"
strNew = "C:\Users\June"
Set db = CurrentDb
For Each td In db.TableDefs
    If InStr(td.Connect, strOld) > 0 Then
        Debug.Print td.name
        Debug.Print "Old Link: " & td.Connect
        td.Connect = Replace(td.Connect, strOld, strNew)
        td.RefreshLink
        Debug.Print "New Link: " & td.Connect
    End If
Next td
db.TableDefs.Refresh

相关问题