[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 734
  • Last Modified:

Problem with Shortcut Menu Bar

I have created a Shortcut Menu Bar and applied it to the text box control but Rightt Click on the control doesn't show it.

I create the control on the Load event of the form.

Any clues?

Thanks in advance.  Control Properties
Sub CreateCopyAddressShortcutMenu()

    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl

   On Error Resume Next
   Application.CommandBars("Copy Address").Delete
   On Error GoTo 0
   
   ' Create the shortcut menu.
    Set cmbRightClick = CommandBars.Add("Copy Address", msoBarPopup, False, True)

    With cmbRightClick
        
        ' Add Copy.
        Set cmbControl = .Controls.Add(Type:=1)
        cmbControl.Caption = "Copy Address"
        cmbControl.OnAction = "=TestMsg()"
        cmbControl.FaceId = 0

    End With
    Set cmbControl = Nothing
    Set cmbRightClick = Nothing
    MsgBox "Done"

End Sub

Public Function TestMsg()

   MsgBox "Test Message"

End Function

Open in new window

0
CRB1609
Asked:
CRB1609
  • 4
  • 3
  • 2
2 Solutions
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You mean it doesn't show when you right click ?

Is there a reason you did this in code as opposed to using the no code method below - from which I've created 100's of custom menus, toolbars and right click menus?

Easily create real, professional Windows menus, toolbars and Right Click menus.

This works in the A2003 (and prior) environment and MDB format.  And they will port (with MDB) into A2007/10 environment and show up on the Add-Ins Ribbon.

Everything you need is here - no code ... see this link:

http://www.jamiessoftware.tk/articles/menubars.html
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
You need the line in Bold below:

    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl

   On Error Resume Next
   Application.CommandBars("Copy Address").Delete
   On Error GoTo 0
   
   ' Create the shortcut menu.
    Set cmbRightClick = CommandBars.Add("Copy Address", msoBarPopup, False, True)

    With cmbRightClick
       
        ' Add Copy.
        Set cmbControl = .Controls.Add(Type:=1)
        cmbControl.Caption = "Copy Address"
        cmbControl.OnAction = "=TestMsg()"
        cmbControl.FaceId = 0
    End With
    Me.ShortcutMenuBar = Application.CommandBars("Copy Address").Name
    Set cmbControl = Nothing
    Set cmbRightClick = Nothing
    'MsgBox "Done"
0
 
Dale FyeCommented:
If the forms Shortcut Menu property is set to No, shortcut menus will not popup, even if the shortcutmenu bar property has a value.  If you want to hide the forms shortcut menus, and still show the popup menus, you must use the MouseUp or down event and test for which button was clicked, something like:

Private Sub txt_Function_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

    If Button = acRightButton Then
        CommandBars("Copy Address").ShowPopup
    End If
   
End Sub
 
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CRB1609Author Commented:
MX suggestion worked fine for a form but I couldn't get it to work in a sub form.  

fyed's suggestion worked for a sub form but the shortcut menu stayed displayed until I moved out of that field.

Any suggestions as to how to make it disappear once clicked on?
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
I guess I didn't see it was a subform. Not sure why that would not work

Also, re "but the shortcut menu stayed displayed until I moved out of that field."
Now, I didn't try that on a subform, but ... once displayed via the mousedown of the right click button ... as soon as I left click anywhere, it goes away.  Are you not getting that result ?  That's pretty much how the default popups work.

Also, again ... was there a particular reason why you are opting for a code solution as opposed to the 'easy way' shown in the link I posted ?

mx
0
 
CRB1609Author Commented:
When I left click on an item in the the shortcut menu it runs the associated function and redisplays itself, almost instantaneously but visibly.  

I didn't use your easy way because, to the best of my knowledge, it is not available in Access 2010.
0
 
Dale FyeCommented:
Try moving the code from the MouseDown event to the MouseUp event.
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"I didn't use your easy way because, to the best of my knowledge, it is not available in Access 2010. "
Well, that is certainly correct.  I didn't realize you were in A2010.

"When I left click on an item in the the shortcut menu it runs the associated function and redisplays itself, almost instantaneously but visibly.  "

That only happens for me if I left click *on* the menu.

mx
0
 
CRB1609Author Commented:
I found a workaround by SendKeys Tab and BackTab but I would prefer it to work properly.

I've shared the points as I appreciate your help.

crb
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now