我想更新的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