Is there a way to OpenCurrentDatabase with a "Press SHIFT" option so nothing runs on its own?
It works also without OpenCurrentDatabase:
Load mdb/accdb as reference. If there is a name conflict, don't get confused, it is only necessary that the respective VBProject is visible in the project explorer. Then find out the appropriate VbProject and via VbComponents you have access to the code modules.
Code:
Private Sub Test()
Dim FilePath As String
FilePath = CurrentProject.Path & "\B.mdb"
On Error Resume Next
Application.References.AddFromFile FilePath
If Err.Number <> 0 Then ' Err 32813 is ok
Debug.Print Err.Number, Err.Description
Err.Clear
End If
On Error GoTo 0
DoSomethingWithVBP FindVbProject(FilePath)
End Sub
Private Function FindVbProject(ByVal FilePath2Check As String) As VBProject
Dim i As Long
For i = 1 To VBE.VBProjects.Count
If VBE.VBProjects(i).FileName = FilePath2Check Then
' compare UNC path if files are in a share
Set FindVbProject = VBE.VBProjects(i)
Exit For
End If
Next
End Function
Private Sub DoSomethingWithVBP(ByVal vbp As VBProject)
Dim vbc As VBComponent
For Each vbc In vbp.VBComponents
Debug.Print vbc.Name
Next
End Sub
Last edited: