Solved

Right Click Shortcut Menu's in Access 2010

Posted on 2013-11-16
3
1,931 Views
Last Modified: 2013-11-17
Previously asked a question about creating right click shortcut menu's in Access 2010.  I use these menu's for navigation on a form by setting them as shortcut menu's.  Here is an example that was included in responses to my original question.

Public Function CreateCMenu()
On Error Resume Next

    CommandBars("MyContext").Delete

    Dim cmb As CommandBar 'Object
    Dim cmbBtn1 As CommandBarButton 'Object
    Dim cmbBtn2 As CommandBarButton 'Object

    Set cmb = CommandBars.Add("MyContext", _
               msoBarPopup, False, False)    ' msoBarPopup = 5
        With cmb
              ' add cut, copy, and paste buttons with the "magic number" technique that assigns
              ' appearance and behavior. The magic number goes in as the second parameter

            .Controls.Add msoControlButton, _
                  21, , , True  ' 21=Cut, msoControlButton=1
            .Controls.Add msoControlButton, _
                      19, , , True  '19= Copy
            .Controls.Add msoControlButton, _
                      22, , , True  ' 22=Paste

' add customized buttons with our caption and function name -- second param is blank
            Set cmbBtn1 = .Controls.Add(msoControlButton, _
                                    , , , True)
            With cmbBtn1
                .BeginGroup = True
                .Caption = "Create New"
                .OnAction = "=CreateNewOrder()"
                .FaceID = 59  'smiley face
            End With
           
            Set cmbBtn2 = .Controls.Add(msoControlButton, _
                                    , , , True)
            With cmbBtn2
                .Caption = "Reset"
                .OnAction = "=ClearOrder()"
            End With
        End With

   
End Function

When I execute 'CreateCMenu' I get the error 'User defined type not defined on the statement  
Dim cmb As CommandBar 'Object

I'm sure I need to add a reference to the DB but I don't know which one.

Anyone know?
0
Comment
Question by:mlcktmguy
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 100 total points
ID: 39654234
Yes. That reference is: Microsoft Office 14.0 Object Library

I use:

    Dim cmb         As Office.CommandBar
    Dim cmbBtn      As Office.CommandBarButton

/gustav
0
 
LVL 1

Author Closing Comment

by:mlcktmguy
ID: 39654628
Exactly what I needed.
I'll be posting more questions about these menu's because the example I used above does not work as a right click 'shortcut menu' on a form.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39654671
You may just need to activate it.
This works for me:
Private Function CreateContextMenuViews()

    Const cstrMenu  As String = "ContextMenuViews"

    Dim cmb         As Office.CommandBar
    Dim cmbBtn      As Office.CommandBarButton

On Error Resume Next

    CommandBars(cstrMenu).Delete

    Set cmb = CommandBars.Add(cstrMenu, msoBarPopup, False, True)
    With cmb
        ' Add cut, copy, and paste buttons with the "magic number" technique that assigns
        ' appearance and behavior. The magic number goes in as the second parameter.
'        .Controls.Add msoControlButton, _
'            21, , , True  ' 21 = Cut
'        .Controls.Add msoControlButton, _
'            19, , , True  ' 19 = Copy
'        .Controls.Add msoControlButton, _
'            22, , , True  ' 22 = Paste

        ' Add customized buttons with our Caption and function name.
        ' Second param is blank.
        Set cmbBtn = .Controls.Add(msoControlButton, , , , True)
        With cmbBtn
            .BeginGroup = True
            .Caption = "Restore Default Settings"
            .OnAction = "=ClearUserSettings()"
            .FaceId = 8     ' Datasheet.
        End With
    End With
    
    ' Activate default (native) shortcut menu for form.
    Me.ShortcutMenuBar = ""  'cstrMenu
    Me.ShortcutMenu = True
    
    Set cmbBtn = Nothing
    Set cmb = Nothing

End Function

Open in new window

/gustav
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dsum Function for List Box Data 7 47
type of query 11 42
Reference Controls on subforms 7 28
Access subform not displaying on tab in naviation form 5 30
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question