Office中国论坛/Access中国论坛
标题:
请教:如何使用ADOX刷新链接表
[打印本页]
作者:
zyz
时间:
2002-8-6 21:06
标题:
请教:如何使用ADOX刷新链接表
Public Sub RefreshLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String)
' strTargetDB: 被链接的数据库路径名
' strProviderString: 连接字符串
' strSourceTbl: 被链接的源表名称
' strLinkTblName: 要重设链接的链接表的名称
Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table
Dim i As Integer
Set catDB = New ADOX.Catalog
catDB.ActiveConnection = CurrentProject.Connection
Set tblLink = catDB.Tables(strLinkTblName)
With tblLink
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB
ink Datasource") = strTargetDB
.Properties("Jet OLEDB
ink Provider String") = strProviderString
.Properties("Jet OLEDB:Remote Table Name") = strSourceTbl
End With
Set catDB = Nothing
End Sub
但是在
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB:Remote Table Name") = strSourceTbl
报错!
请教![em26]
(DAO_链接表_ODBC-相关文章技巧链接):
Access使用ADOX刷新链接表的函数
作者:
明莱
时间:
2002-8-6 23:40
好像用DAO刷新更方便吧!
作者:
zyz
时间:
2002-8-7 00:50
已通過的代碼:
Public Sub NewLinkedExternalTableMdb()
' strTargetDB: 被链接的数据库路径名
' strProviderString: 连接字符串
' strSourceTbl: 被链接的源表名称
' strLinkTblName: 要重设链接的链接表的名称
' 作者:朱亦文
Dim strTargetDB() As String
Dim strProviderString() As String
Dim strSourceTbl() As String
Dim strLinkTblName() As String
Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table
Dim tmpLink As ADOX.Table
Dim i As Integer
Dim j As Integer
Set catDB = New ADOX.Catalog
catDB.ActiveConnection = CurrentProject.Connection
i = catDB.Tables.Count
ReDim strTargetDB(i)
ReDim strProviderString(i)
ReDim strSourceTbl(i)
ReDim strLinkTblName(i)
i = 1
For Each tmpLink In catDB.Tables
If tmpLink.Properties("Jet OLEDB:Create Link") Then
If Trim(tmpLink.Properties("Jet OLEDB:Remote Table Name")) <> "" Then
Debug.Print tmpLink.Name & " | " & tmpLink.Properties("Jet OLEDB:Remote Table Name")
strLinkTblName(i) = tmpLink.Name
strTargetDB(i) = tmpLink.Properties("Jet OLEDB
ink Datasource")
strProviderString(i) = tmpLink.Properties("Jet OLEDB
ink Provider String")
strSourceTbl(i) = tmpLink.Properties("Jet OLEDB:Remote Table Name")
Do While InStr(1, strTargetDB(i), "\") <> 0
strTargetDB(i) = Mid(strTargetDB(i), InStr(1, strTargetDB(i), "\") + 1, Len(strTargetDB(i)))
Loop
strTargetDB(i) = CurrentProject.Path & "\" & strTargetDB(i)
i = i + 1
End If
End If
Next
j = i - 1
For i = 1 To j
catDB.Tables.Delete strLinkTblName(i)
Set tblLink = New ADOX.Table
With tblLink
.Name = strLinkTblName(i)
Set .ParentCatalog = catDB
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB
ink Datasource") = strTargetDB(i)
.Properties("Jet OLEDB:Link Provider String") = strProviderString(i)
.Properties("Jet OLEDB:Remote Table Name") = strSourceTbl(i)
End With
catDB.Tables.Append tblLink
Set tblLink = Nothing
Next
Set catDB = Nothing
End Sub
[em26]
作者:
fanren
时间:
2006-4-7 17:32
如果后台数据库有密码怎样连?
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3