简体   繁体   中英

MS Access How to Update Linked Table Path while Keeping the Format

I have around 20 linked tables in Access sourcing from.csv files, with the first row used as table headers. However, I can't seem to keep the headers any time I update source path, so I have to manually delete and relink them every single time and it's been painful. Any idea how to keep the table format and properties after source path change?

Can use VBA to modify links. Example code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM