Solved Create context menu in access form gives invalid procedure call error (1 Viewer)

zelarra821

Registered User.
Local time
Today, 02:51
Joined
Jan 14, 2019
Messages
343
I have a function in a module to create a context menu, but when I run it I get the error "5 Invalid Argument or Procedure Call", and I don't know where the error is.

This is the code:

Code:
Public Function MenuContextual()
On Error GoTo err_lbl
Dim myBar As CommandBar
CommandBars("ShortcutMenu").Delete
Set myBar = CommandBars _
    .Add(Name:="ShortcutMenu", Position:=msoBarPopup, Temporary:=False)
With myBar
    .Controls.Add Type:=msoControlButton, ID:=19
    .Controls.Add Type:=msoControlButton, ID:=22
End With
myBar.ShowPopup
Salida:
    Exit Function
err_lbl:
    MsgBox "MenuContextual: " & Err.Number & " " & Err.Description, vbInformation, NombreBD
    Resume Salida
End Function

I don't know if that error can be solved, or it will be necessary to do an on error resume next to avoid the problem.

Thanks!
 

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
7,488
So have you walked through the code with F8 after setting a breakpoint.?
 

zelarra821

Registered User.
Local time
Today, 02:51
Joined
Jan 14, 2019
Messages
343
Yes, and it gives me an error in different lines depends on the occasion. I have recorded a video for you to see for yourself.

 

Gasman

Enthusiastic Amateur
Local time
Today, 02:51
Joined
Sep 21, 2011
Messages
7,488
Well I appreciate the effort of the video, but it hung at 06:02.
I have tried to run just your code and I get that error on the second run.

Not something I have played with I admit, as I was only approaching it from a coding perspective.
This link does not show any delete, so perhaps the .Add replaces the menu?
https://docs.microsoft.com/en-us/of...ortcut-menu-for-a-form-form-control-or-report

However you cannot delete it if it does not exist?, so there must be a way to test for it?

You will need to wait for an expert. Sorry. :(
 
Last edited:

zelarra821

Registered User.
Local time
Today, 02:51
Joined
Jan 14, 2019
Messages
343
Yes, I have read that article. In fact, I've read all four or five of Office articles about it. This last code is copied from that help. I added the one to eliminate because it gave me the error, to see if that would solve it. I want to know if it can be fixed before I put an On Error Resume Next which skips the error.

Anyway thank you very much.
 

Users who are viewing this thread

Top Bottom