Solved ShortCut Menu .OnAction

HASAN-1993

Member
Local time
Today, 08:22
Joined
Jan 22, 2021
Messages
89
How Can I Call Function On The Same Form
.OnAction = "UnitePrice"
.OnAction = "=UnitePrice"
.OnAction = "=UnitePrice()"
.OnAction = "MainForm.UnitePrice()"
All of these did not work

It only works from the main module page
 
Did you declare the function as Public?
 
Yes, and it is already in the same form
 
Access Cannot Run The Macro Or Callback Function

Although if I tries to call function from one of the button, it will work
 
Cannot Find The Name You Entered In the Expression

I just put a msgbox to make sure the function is working
 
Can you show your code for both the CommandBar and UnitPrice?
 
Public Function UnitPrice()
Msgbox "Hello"
End Function

Public Function ShortCutMenuM()
Set Button = .Controls.Add(msoControlButton)
With Button
.Caption = "PriceName"
.OnAction = "=UnitPrice()"
End With
End Function
 
If this is your actual code, change
.OnAction = "=UnitPrice()"
to
.OnAction = ="UnitPrice"

Your open quotes were on the wrong side of the "=" sign
 
If the equal sign is inserted twice next to each other, the code will not work at all
 
Also,
Code:
'Add
Public Function ShortCutMenuM()
    Set myShortCutMenu = CommandBars("Custom")
    Set Button = myShortCutMenu.Controls.Add(msoControlButton)
    With Button
        .Caption = "PriceName"
        .OnAction = "UnitPrice"
    End With
End Function
 
Also,
Code:
'Add
Public Function ShortCutMenuM()
    Set myShortCutMenu = CommandBars("Custom")
    Set Button = myShortCutMenu.Controls.Add(msoControlButton)
    With Button
        .Caption = "PriceName"
        .OnAction = "UnitPrice"
    End With
End Function
Of course, this is my full code, but it only works from the main module, either from the same form, not
 
The action will only run from the form inside of which the action occurs. Remember that a sub-form is a separate form that has to be separately designed. It is activated only because the sub-form control points to it.

So.... is your .OnAction declaration in the form where that action will really occur / be detected?
 
The action will only run from the form inside of which the action occurs. Remember that a sub-form is a separate form that has to be separately designed. It is activated only because the sub-form control points to it.

So.... is your .OnAction declaration in the form where that action will really occur / be detected?
yes, on the same
 
I tried to put the function on the main Form and call it from the subform
And I tried to put it in the same subform and call it from the subform
All this did not work
 
So the next question is, when you say it doesn't work form anything except the main module page, are those events ALSO linked on the sub-form; i.e. repeated each place where you want them to run?

EDIT: Obviously our posts crossed in transmission.
 
So the next question is, when you say it doesn't work form anything except the main module page, are those events ALSO linked on the sub-form; i.e. repeated each place where you want them to run?

EDIT: Obviously our posts crossed in transmission.
I just put a msgbox to make sure the function is working
 

Users who are viewing this thread

Back
Top Bottom