2

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?

Andre
  • 26,751
  • 7
  • 36
  • 80
Klaus
  • 31
  • 3
  • You can try `Set appAccess = CreateObject("Access.Application")` and work with that object instead. – Andre Nov 20 '20 at 19:12
  • Thanks! 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) .Visible = True .UserControl = True Call deleteBrokenReferences(appAccess) .CloseCurrentDatabase End With Set appAccess = Nothing Is there a possibility to save the changes? – Klaus Nov 21 '20 at 14:01
  • Please edit your question and add the code there, and also add the code of `deleteBrokenReferences()` – Andre Nov 21 '20 at 17:29
  • Hi Andre, I tried to convert my second comment in a more readable form - I inserted it into my first question. – Klaus Nov 23 '20 at 10:33
  • Yes, I noticed. It is now a good question, but I don't know the answer. :( -- added relevant tag. – Andre Nov 23 '20 at 10:44
  • So, thanks once more! I'll try to find an answer, and if I succeed, I'll publish it here. – Klaus Nov 23 '20 at 11:34

1 Answers1

1

The reason for my problem was that none of the three mutually dependent databases could be opened exclusively. I solved the problem by creating a new database which opens each of the three databases separately and performs the updates of code references and table links. But once more: Thank you Andre for your valuable input!

Klaus
  • 31
  • 3