Hi,
I'm trying to add a context menu to a listbox, so I've found this code (that fires up on mouse_up event), but I always get a type mismatch on code row no.30 (Set combo = .Controls.Add(Type:=msoControlButton)
I'm using Access 2016.
Any suggestions how to fix it? or another alternative for a context menu?
Thanks in advance!
Udi
Code:
Public Sub SetUpContextMenu()
' Note: This requires a reference to Microsoft Office Object Library
5 Dim combo As CommandBarComboBox
' Since it may have been defined in the past, it should be deleted,
' or if it has not been defined in the past, the error should be ignored
10 On Error Resume Next
CommandBars("MyListControlContextMenu").Delete
15 On Error GoTo 0
' Make this menu a popup menu
20 With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
' Provide the user the ability to input text using the msoControlEdit type
25 Set combo = .Controls.Add(Type:=msoControlEdit)
combo.Caption = "Lookup Text:" ' Add a label the user will see
combo.OnAction = "getText" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
30 Set combo = .Controls.Add(Type:=msoControlButton)
combo.BeginGroup = True ' Add a line to separate above group
combo.Caption = "Lookup Details" ' Add label the user will see
combo.OnAction = "LookupDetailsFunction" ' Add the name of a function to call
' Provide the user the ability to click a menu option to execute a function
40 Set combo = .Controls.Add(Type:=msoControlButton)
combo.Caption = "Delete Record" ' Add a label the user will see
combo.OnAction = "DeleteRecordFunction" ' Add the name of the function to call
50 End With
End Sub