我已经参考了其他页面来解决我的问题,但我仍然无法让它工作。鉴于我有下面的三个例子,我感觉有点慢,但仍然无法弄清楚。
以编程方式更改链接表位置
链接表MS Access 2010更改连接字符串
更新 Access 链接表以使用 UNC 路径
这是我正在使用的代码:
Dim tdf As TableDef
Dim db As Database
Set db = CurrentDb
Set tdf = db.TableDefs("DeviceListT")
tdf.Connect = "ODBC;DATABASE=" & CurrentProject.path _
& "\HarmonicProfileDatabase_be.accdb"
tdf.RefreshLink
问题是当我运行它时会弹出一个窗口。
我不太确定我应该用它做什么,也不希望它首先弹出,因为我将把 MS 访问文件提供给其他人,他们也不知道如何处理这个窗口。
您正在使用 SQL Server 引用但链接 MS Access。对于 MS Access,不需要 ODBC 链接,只需引用 DATABASE:
DBFile = CurrentProject.path & "\HarmonicProfileDatabase_be.accdb
''Check the file exists
strFile = Dir(DBFile)
If strFile <> "" Then
With CurrentDb
For Each tdf In .TableDefs
''Check that this is a linked table
''It can be useful to use table of tables instead
If tdf.Connect Like "*HarmonicProfileDatabase_be.accdb*" Then
tdf.Connect = ";DATABASE=" & DBFile
tdf.RefreshLink
End If
Next
End With
MsgBox "Link HarmonicProfileDatabase_be.accdb"
Else
MsgBox "Problem"
End If
您还可以使用:
sConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
& DBFile & ";Jet OLEDB:Database Password=pw;"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)