I found this code to produce a context menu for runtime users.
Ive just created a new module, pasted this code and called it from the form. However I've saved the module but it doesn't come up in the dropdown section for the Shortcut Menu Bar.
Any ideas what I'm doing wrong?
highlighted
cbar As CommandBar
I'm getting a Compile error: User-defined type not defined
Ive just created a new module, pasted this code and called it from the form. However I've saved the module but it doesn't come up in the dropdown section for the Shortcut Menu Bar.
Any ideas what I'm doing wrong?
Code:
Option Compare Database
Option Explicit
Private Sub CreateContextMenu()
Const strMenuName As String = "Form1_CommandBar"
Dim cbar As CommandBar
Dim bt As CommandBarButton
Set cbar = CommandBars.Add(strMenuName, msoBarPopup, , False)
Set bt = cbar.Controls.Add
bt.Caption = "Cut"
bt.OnAction = "=fCut()"
bt.FaceId = 21
Set bt = cbar.Controls.Add
bt.Caption = "Copy"
bt.OnAction = "=fCopy()"
bt.FaceId = 19
Set bt = cbar.Controls.Add
bt.Caption = "Paste"
bt.OnAction = "=fPaste()"
bt.FaceId = 22
End Sub
Function fCut()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Cut")
End Function
Function fCopy()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Copy")
End Function
Function fPaste()
On Error Resume Next
Application.CommandBars.ExecuteMso ("Paste")
End Function
highlighted
cbar As CommandBar
I'm getting a Compile error: User-defined type not defined