Ms access 以编程方式更改ms access中链接表的连接
我已经参考了我的问题的其他网页,但我仍然无法让这个工作。我觉得有点慢,因为我下面有三个例子,但仍然无法理解这一点 以下是我正在使用的代码:Ms access 以编程方式更改ms access中链接表的连接,ms-access,odbc,vba,linked-tables,Ms Access,Odbc,Vba,Linked Tables,我已经参考了我的问题的其他网页,但我仍然无法让这个工作。我觉得有点慢,因为我下面有三个例子,但仍然无法理解这一点 以下是我正在使用的代码: Dim tdf As TableDef Dim db As Database Set db = CurrentDb Set tdf = db.TableDefs("DeviceListT") tdf.Connect = "ODBC;DATABASE=" & CurrentProject.path _
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 access文件给其他人,他们也不知道如何处理这个窗口 您正在使用SQL Server引用,但正在链接MS Access。对于MS Access,您不需要ODBC链接,只需参考数据库:
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;"