Hi,
I have created 3 custom context menu, for different subforms, however It seems that only one can work. Is there a limit in Access for that, or is my code wrong ?
Here is my code ( for one of the menus, all other are basically the same):
This code is in a module
Code:
Sub CreateContextMenu1()
Dim cmbRightClick1 As CommandBar
Dim cmbButton1 As CommandBarButton
Dim cmbButton2 As CommandBarButton
Dim MenuName As String
MenuName = "ContextMenu1"
' I also tried deleting other commandbars first, but not working
'On Error Resume Next
'CommandBars("ContextMenu2").Delete
'CommandBars(#ContextMenu3").Delete
Set cmbRightClick1 = Application.CommandBars.Add(MenuName1, msoBarPopup, False, True)
Set cmbButton1 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
cmbButton1.Caption = "Import"
cmbButton1.OnAction = "Import_All"
Set cmbButton2 = cmbRightClick1.Controls.Add(msoControlButton, , , , True)
cmbButton2 = "Export"
cmbButton2.OnAction = "Exprot_All"
Set cmbButton1 = Nothing
Set cmbButton2 = Nothing
Set cmbrightClick1 = Nothing
End Sub
And this is in a Form_Load event
Code:
Private Sub Form_Load()
On Error Resume Next
Call CreateContextMenu1
End Sub
References are set to Microsoft Office 14.0 Object library. All context menu are set to subforms controls - via property Shorcut Menu bar, after 1st time running of codes as instructed by Microsoft.
Any help much appreciated !!!