How to find out the trigger of a function? (1 Viewer)

KitaYama

Well-known member
Local time
Today, 16:14
Joined
Jan 6, 2022
Messages
1,541
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:

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:14
Joined
May 21, 2018
Messages
8,529
Afaik you need to pass in an optional parameter identifying the calling procedure
 

KitaYama

Well-known member
Local time
Today, 16:14
Joined
Jan 6, 2022
Messages
1,541
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

Top Bottom