Results 1 to 3 of 3
  1. #1
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172

    How to call a custom functon from a custom right click menu

    I have a need to call custom functions from a custom right click menu. I have searched & searched, but the internet don't seem to go beyond creating the custom menu. I need to call custom procedures. The following is my simple custom menu an following that is my simple custom procedure.



    ' simple custom shortcut menu
    Function modRightClick_CreateMyShortcutMenu()
    Dim cmbRightClick As Office.CommandBar
    ' Create the shortcut menu.
    Set cmbRightClick = CommandBars.Add("myRightClick", msoBarPopup, False, False)
    ' Add custom command to call a procedure
    With cmbRightClick
    .Controls.Add , 1, modRightClick_testFunction, , False
    End With
    End Function

    ' simple custom procedure
    Function modRightClick_testFunction()
    ' test procedure
    MsgBox "Yes, it did work"
    End Function

    Right clicking an object does produce the short cut menu option. However, it just displays an empty box (which is what the instructions say will happen). But, clicking that empty box does not call the custom procedure. Help will be appreciated.

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Try this -
    Code:
    Sub CreateMyShortcutMenu()
     Dim newButton As CommandBarControl,Dim cmbRightClick As Office.CommandBar
    Set cmbRightClick = CommandBars.Add("myRightClick", msoBarPopup, False, False)
    Set newButton = cmbRightClick.Controls.Add(msoControlButton, 1, , , False)
     
           With newButton
                 .style = msoButtonIconAndCaption
                .Caption = "&Invoice"                                              'Menu caption
    '            .Picture = CurrentProject.path & "\Images\Invoice.png"  ' Path to the picture
                .OnAction = "=Invoice()"
            End With
    End Sub
    To make this menu available in more than one forms, put the custom function in public module.
    Code:
    Public Function Invoice()
    MsgBox "You clicked on Invoice"
    End Function

  3. #3
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    That worked like a charm. Thank you very much.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Print Preview Custom Shortcut Menu
    By Swatskeb in forum Modules
    Replies: 2
    Last Post: 05-22-2014, 08:02 PM
  2. A2000 to A2010 custom menu bar conversion
    By Petesmith673 in forum Programming
    Replies: 0
    Last Post: 04-30-2013, 02:36 PM
  3. Replies: 3
    Last Post: 04-19-2013, 07:09 AM
  4. Custom button click to Built-in pop-up filter
    By LindaRuble in forum Reports
    Replies: 1
    Last Post: 08-23-2012, 07:00 PM
  5. custom shortcut menu help!
    By ninachopper in forum Access
    Replies: 5
    Last Post: 09-05-2010, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums