我想更新的60+表的鏈接表引用/ EXCEL在MS Accecss數據庫文件:如何編程更新所有鏈接表引用在MS Access
但是我不想手動進入所有60歲以上的文件路徑只需要簡單地改變「F:」 ......」改爲‘E:......’
這又如何調動羣衆通過編程完成
我想更新的60+表的鏈接表引用/ EXCEL在MS Accecss數據庫文件:如何編程更新所有鏈接表引用在MS Access
但是我不想手動進入所有60歲以上的文件路徑只需要簡單地改變「F:」 ......」改爲‘E:......’
這又如何調動羣衆通過編程完成
以下代碼執行3件事:
Function relink_tables() If Left(CurrentDb().Name, 2) = "C:" Or Left(CurrentDb().Name, 2) = "B:" Then Source = "local" Else: Source = "network" End If Set rs = CurrentDb.OpenRecordset("select * from [linked table source] where source='" & Source & "'") Source = rs.Fields("path") For Each R In References If InStr(R.Name, "Common Tables") > 0 Then Application.References.Remove R Next R Application.References.AddFromFile Source x = 0 Set TDefs = CurrentDb().TableDefs For Each table In TDefs If InStr(table.Connect, "Common Tables") = 0 Then GoTo NT table.Connect = ";DATABASE=" & Source table.RefreshLink x = x + 1 NT: Next table Finish: MsgBox "remapped " & x & " tables" End Function
這是一個一杆?如果是的話,這可能是矯枉過正,並會需要一些時間來poerfection,但上檔,你不會需要一個單獨的表,讓您的引用 如果你熟悉VBA你可以使用這樣的事情:
Dim td As DAO.TableDef
Dim strPath as string
For Each td In CurrentDb.TableDefs
If (td.Attributes And dbAttachedTable) = dbAttachedTable Then
strPath = Mid(td.Connect, 11)
If Left(strPath, 1) = "E" Then
strPath = "F" & Mid(strPath, 2)
td.Connect = ";DATABASE=" & strPath
td.RefreshLink
End If
End If
Next
這是針對沒有密碼的ODBC數據庫。如果你的連接字符串更復雜,你將不得不進行調整。 這裏是所有可能的連接字符串的列表。 Microsoft DAO Connection Strings
我知道的唯一編程方式是刪除所有鏈接表並重新鏈接它們。可能有一種方法可以從系統表中讀取鏈接表及其屬性,以便您可以使用它來執行此操作,但我從來沒有這樣做過。 看看這裏:http://stackoverflow.com/questions/25579591/get-the-name-of-l-table-table-and-linked-table-in-vba – SunKnight0