【发布时间】:2011-02-22 13:52:18
【问题描述】:
我在 access 2007 中创建了一个用于更新链接表的模块,但我想从 vb6 运行这个模块。我试过微软的这段代码,但没有用。
Sub AccessTest1()
Dim A As Object
Set A = CreateObject("Access.Application")
A.Visible = False
A.OpenCurrentDatabase (App.Path & "/DataBase/acc.accdb")
A.DoCmd.RunMacro "RefreshLinks"
End Sub
我的目标是让我的程序将所有链接表更新为新链接,以防该程序已在其他计算机上使用
如果你想看一下模块程序,这里是:
Sub CreateLinkedJetTable()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
' Open the catalog.
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
' Create the new table.
tbl.Name = "Companies"
Set tbl.ParentCatalog = cat
' Set the properties to create the link.
tbl.Properties("Jet OLEDB:Link Datasource") = CurrentProject.Path & "/db3.mdb"
tbl.Properties("Jet OLEDB:Remote Table Name") = "Companies"
tbl.Properties("Jet OLEDB:Create Link") = True
' To link a table with a database password set the Link Provider String
' tbl.Properties("Jet OLEDB:Link Provider String") = "MS Access;PWD=Admin;"
' Append the table to the tables collection.
cat.Tables.Append tbl
Set cat = Nothing
End Sub
Sub RefreshLinks()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
' Open the catalog.
cat.ActiveConnection = CurrentProject.Connection
Set tbl = New ADOX.Table
For Each tbl In cat.Tables
' Verify that the table is a linked table.
If tbl.Type = "LINK" Then
tbl.Properties("Jet OLEDB:Link Datasource") = CurrentProject.Path & "/db3.mdb"
' To refresh a linked table with a database password set the Link Provider String
'tbl.Properties("Jet OLEDB:Link Provider String") = "MS Access;PWD=Admin;"
End If
Next
End Sub
【问题讨论】:
-
怎么没用?没有这个,任何答案都只是猜测。
-
你有一个名为“RefreshLinks”的宏吗?
-
@David-W-Fenton 经过长时间的搜索,我发现我没有马可,为了得到马可,我不得不调用这个问题解决的函数
标签: ms-access vba vb6 ms-access-2007