Here is an example:
Sub MakeMenu()
Dim cbr As CommandBar
Dim cbx As CommandBarComboBox
On Error Resume Next
CommandBars("MyMenu").Delete
On Error GoTo ErrHandler
Set cbr = CommandBars.Add(Name:="MyMenu", MenuBar:=True)
Set cbx = cbr.Controls.Add(msoControlDropdown)
With cbx
.Caption = "Reports"
.Style = msoComboLabel
.AddItem "Report 1"
.AddItem "Report 2"
.AddItem "Report 3"
.AddItem "Report 4"
.ListIndex = 1
.OnAction = "=OpenMyReport()"
End With
ExitHandler:
Set cbr = Nothing
Set cbx = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Function OpenMyReport()
Dim strChoice As String
On Error GoTo ErrHandler
DoCmd.Hourglass True
strChoice = CommandBars("MyMenu").Controls("Reports").Text
DoCmd.OpenReport ReportName:=strChoice, View:=acViewPreview
ExitHandler:
DoCmd.Hourglass False
Exit Function
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Function
Sub RemoveMenu()
On Error Resume Next
CommandBars("MyMenu").Delete
End Sub
The MakeMenu procedure will create a custom menu bar with one menu, titled My Menu.
This menu has 4 items, labeled Report 1 to Report 4.
You only need to run this procedure once; the custom menu bar will be stored in the database.
It will normally be invisible. To make it visible for a specific form, set the Menu Bar property of the form to MyMenu (you
must have run MakeMenu before you do this).
When you open the form, Access will display the Add-Ins tab in the ribbon; this tab will contain the menu.
When you select an item from the dropdown menu, the OpenMyReport function will be executed. It inspects the selected item and tries to open the corresponding report. (This is just an example - you can make the function do whatever you want)
If you want to delete the menu from the database, run the procedure RemoveMenu.