How to find out the trigger of a function?

KitaYama

Well-known member
Local time
Today, 14:32
Joined
Jan 6, 2022
Messages
1,689
I have a function that can be called from a commandbar on some forms or from ribbon or from other functions and subs.

How can I check the trigger? The function has been called from a commandbar or a function/sub?

For now, I ended up deleting the commandbar after each use and recreating it when necessary. Then used a syntax like following.
Is there any simpler way to check the trigger of a function?

Code:
Public Function MyFunction (Optional Params as string)

    If isCommandBar("MyCommandBar") Then
        Params = Nz(Application.CommandBars.ActionControl.Parameter, "")
    End If

    ' Do Something Here

End Function


Thanks.
 
Last edited:
Afaik you need to pass in an optional parameter identifying the calling procedure
 
Afaik you need to pass in an optional parameter identifying the calling procedure
Instead of deleting and recreating the commandbar, based on your advice, I changed my code to:

Code:
Public Function MyFunction (Optional Params as string, Optional Trigger as string)
    
    If Trigger="" then
        ' has been called by commandbar
        .....
    else
        ' has been called by another function/sub
        ......
    End If

    ' Do common tasks Here

End Function

The code seems better than what it was.
Thanks.
 

Users who are viewing this thread

Back
Top Bottom