Solved Calling a procedure from an add-in

Superpat

Member
Local time
Today, 23:23
Joined
Aug 15, 2020
Messages
121
Hello, I have a problem calling a procedure from an add-in to a main file.
Code:
Sub InsererTeteTitreModule()
        Dim sCheminProjet As String
        sCheminProjet = TrouverTag()
        If sCheminProjet <> "" Then
        
    Application.Run sCheminProjet & "InsererEnTeteTitreModule"
        
                'Call InsererEnTeteTitreModule
                Debug.Print "InsererEnTeteTitreModule appelé"
            End If
End Sub
To open in :
EssaiBarreOutils8.accdb
---> InsertionBarreOutils
--------> BrandNewBarAndButton
Click on the menu : "Entête module"
 

Attachments

The call via Application.Run ...\EssaiBarreOutils8.InsererEnTeteTitreModule only works if the file has the extension accda.
It is much easier if the VBA project is already loaded: Application.Run "InsererEnTeteTitreModule"

I think this is the wrong direction.
If you use an add-in file directly from the application, you can view this file as a library that is used via Latebinding.

If I interpret your project correctly, you want to edit the codemodules of an Access application automatically.
Why do you need to use code from the application? I would rather create a “real” add-in for this and install all the code there.
Then the add-in can be used for any desired application.
You would then only have to load the Access add-in at the beginning via the Access ribbon (menu add-ins). The rest then runs via the command bar in the VBA editor.
A COM add-in could be loaded automatically.
 
Last edited:
Ok, I'll use your method, which I thought was better...
I've got a form that I've put in the Add-in and which I use to list the modules, then the functions, and I can't open it because, with my open function, I only open the modules and not the form sheet, so it can't find it.
I found :
Code:
Private Sub Ouvrirautreformulaire()
        Dim autreBdd As Access.Application
        Dim chemin As String

        chemin = Application.CurrentProject.Path & "\EssaiBarreOutils_09AddIn.accda"
        Set autreBdd = CreateObject("Access.Application")

        With autreBdd
                .OpenCurrentDatabase chemin
                .Visible = True
                .UserControl = True
                .DoCmd.OpenForm "f_InsertionModule", acNormal, , , , acWindowNormal
        End With

End Sub
Thank you, I'll switch to resolute.
 
Last edited:
To list the code modules of the application, you must find the right VB project.

Inside add-in:

a) Check via file path
Code:
private m_CurrentVbProject as VBIDE.VBProject

Private Property Get CurrentVbProject() As VBIDE.VBProject

   Dim Proj As VBIDE.VBProject
   Dim CurrentDbName As String

   If m_CurrentVbProject Is Nothing Then
      Set m_CurrentVbProject = VBE.ActiveVBProject
      'Check if the correct VbProject is selected (must be the one from CurrentDb):
      CurrentDbName = UncPath(CurrentDb.Name)  ' UncPath if stored in network share
      If m_CurrentVbProject.FileName <> CurrentDbName Then
         Set m_CurrentVbProject = Nothing
         For Each Proj In VBE.VBProjects
            If Proj.FileName = CurrentDbName Then
               Set m_CurrentVbProject = Proj
               Exit For
            End If
         Next
      End If
   End If
 
   Set CurrentVbProject = m_CurrentVbProject

End Property

or

b) with WizHook: (see https://team-moeller.de/?Tipps_und_Tricks:Wizhook-Objekt:DbcVbProject)
Code:
Private Property Get CurrentVbProject() As VBIDE.VBProject
   WizHook.Key = 51488399
   CurrentVbProject = WizHook.DbcVbProject
End Property

=>
Code:
    Dim vbc As VBComponent
    For Each vbc In CurrentVbProject.VBComponents
        Debug.Print vbc.Name
    Next
 
Last edited:

Users who are viewing this thread

Back
Top Bottom