【发布时间】:2025-12-28 02:30:12
【问题描述】:
我正在使用具有使用 DAO 代码的子例程的 Access 2003 数据库。此代码循环遍历表定义并刷新 ODBC 连接字符串。我想将其转换为 ADO,因此我不必引用 DAO 对象库。这是代码...
Public Sub RefreshODBCLinks(newConnectionString As String)
Dim db As DAO.Database
Dim tb As DAO.TableDef
Set db = CurrentDb
For Each tb In db.TableDefs
If Left(tb.Connect, 4) = "ODBC" Then
tb.Connect = newConnectionString
tb.RefreshLink
Debug.Print "Refreshed ODBC table " & tb.Name
End If
Next tb
Set db = Nothing
MsgBox "New connection string is " & newConnectionString, vbOKOnly, "ODBC Links refreshed"
End Sub
我不确定的部分是如何遍历表并获取/设置它们的连接字符串。
【问题讨论】:
-
链接表是一个 Jet 对象,因此,DAO 是用于更改它的正确接口。