【发布时间】:2020-11-20 17:04:41
【问题描述】:
在 Access 数据库(“CurrentDB”)的 VBA 代码中,我打开另一个数据库(Application.DBEngine.OpenDatabase(...))。
我想更新第二个数据库中的一些库引用。但是由于 References 对象是 Application 对象的属性(而不是我认为应该是 Database 对象的属性)。
我只能列出和更改 CurrentDB 的引用,而不是第二个的引用。 知道如何访问第二个数据库的引用吗?
Andre,谢谢你的第一个回答,它真的让我更进一步!现在我面临下一个问题:我打开第二个数据库,删除所有损坏的引用(它们真的消失了),关闭第二个数据库 - 当我再次打开它时,损坏的引用又回来了。这是我的代码:
Set appAccess = CreateObject("Access.Application")
With appAccess
Call .OpenCurrentDatabase(sPathMasterDb, False)
' It makes no difference if I use the next two statements or not:
.Visible = True
.UserControl = True
Call deleteBrokenReferences(appAccess)
.CloseCurrentDatabase
End With
Set appAccess = Nothing
Private Sub deleteBrokenReferences(app As Application)
Dim aRef As Access.Reference
If app.BrokenReference Then
For Each aRef In app.References
If aRef.IsBroken Then
app.References.Remove aRef
End If
Next aRef
End If
End Sub
调用“deleteBrokenReferences”后,我在新的 MS Access 实例中打开第二个数据库,损坏的引用消失了。但在“.CloseCurrentDatabase”执行后又回来了。
是否有可能在关闭第二个数据库之前保存更改?
【问题讨论】:
-
您可以尝试
Set appAccess = CreateObject("Access.Application")并改为使用该对象。 -
谢谢!现在我面临下一个问题:我打开第二个数据库,删除所有损坏的引用(它们真的消失了),关闭第二个数据库 - 当我再次打开它时,损坏的引用又回来了。这是我的代码: Set appAccess = CreateObject("Access.Application") With appAccess Call .OpenCurrentDatabase(sPathMasterDb, False) .Visible = True .UserControl = True Call deleteBrokenReferences(appAccess) .CloseCurrentDatabase End With Set appAccess = Nothing 有没有可能保存更改?
-
请编辑您的问题并在此处添加代码,并添加
deleteBrokenReferences()的代码 -
嗨,安德烈,我试图将我的第二条评论转换为更易读的形式 - 我将它插入到我的第一个问题中。
-
是的,我注意到了。现在这是一个很好的问题,但我不知道答案。 :( -- 添加了相关标签。
标签: ms-access reference external ms-access-2016