You are here:   Home > Access - Ribbons > Menus / Toolbars > Toolbars

Toolbars

As described in Menus / Toolbars there is no editor for menus / toolbars in Access 2007. This means that there is no editor for context menus either.

You can create and maintain context menus using VBA and the CommandBars.

Bug?: Context Menu Not Visible In Sub Form (Description and Solution)


Sample for 2 context menus.

Function(s) to be copied to a standard module:
You have to make sure that functions creating context menus are executed during start of the database, e.g. using the autoexec macro.

Option Compare Database
Option Explicit
  
Public Function CreateCMenu()
On Error Resume Next
    CommandBars("MyContext").Delete
    Dim cmb As CommandBar
    Set cmb = CommandBars.Add("MyContext", _
               msoBarPopup, False, False)
   
        With cmb
            .Controls.Add msoControlButton, _
                      21, , , True  ' Cut
            .Controls.Add msoControlButton, _
                      19, , , True  ' Copy
            .Controls.Add msoControlButton, _
                      22, , , True  ' Paste
        End With
End Function
  
Public Function CreateCMenu1()
On Error Resume Next
    CommandBars("MyContext1").Delete
    Dim cmb     As CommandBar
    Dim cmbBtn1 As CommandBarButton
    Dim cmbBtn2 As CommandBarButton
    Dim cmbBtn3 As CommandBarButton
   
    Set cmb = CommandBars.Add("MyContext1", _
               msoBarPopup, False, False)
   
        With cmb
            Set cmbBtn1 = .Controls.Add(msoControlButton, _
                                    , , , True)
            With cmbBtn1
                .Caption = "My Button 1"
                .OnAction = "=fncOnActionBtn1()"
            End With
           
            Set cmbBtn2 = .Controls.Add(msoControlButton, _
                                    , , , True)
            With cmbBtn2
                .Caption = "My Button 2"
                .OnAction = "=fncOnActionBtn2()"
            End With
           
            Set cmbBtn3 = .Controls.Add(msoControlButton, _
                                    , , , True)
            With cmbBtn3
                .Caption = "My Button 3"
                .OnAction = "=fncOnActionBtn3()"
                .BeginGroup = True
                .FaceId = 59
            End With
        End With
End Function
  
Public Function fncOnActionBtn1()
    MsgBox "Button 1", vbInformation
End Function
  
Public Function fncOnActionBtn2()
    MsgBox "Button 2", vbInformation
End Function
  
Public Function fncOnActionBtn3()
    MsgBox "Button 3", vbInformation
End Function

 

You can find this sample in Sample DB 3

Further Links see section Commandbars.

 

 

 

Last Updates:

18.03.2021
New Download added. ...

25.10.2018
Update Site "Trusted Locations" ...

22.10.2018
New Download added. ...

08.04.2018
IDBE RibbonCreator 2016 (x86 and x64) for Office 2013 and Office 2016 - new release. ...

 

Last update: