In the VBA code of an Access database (the "CurrentDB"), I open another database (by Application.DBEngine.OpenDatabase(...)
).
and I'd like to update some library references within this second database. But as the References object is a property of the Application object (and not of the Database object as it should be in my opinion).
I only can list and change the references of the CurrentDB, not of the second one. Any idea how to access the References of the second database?
Andre, thank you for your first answer, it really brought me a big piece further! Now I face the next problem: I open the second database, delete all broken references (they really disappear), close the second database - and when I open it again, the broken references are back. Here's my code:
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
After the call of "deleteBrokenReferences", I open the second database in a new instance of MS Access, and the broken references are gone. But after the execution of ".CloseCurrentDatabase" they are back again.
Is there a possibility to save the changes before closing the second database?