property Command.ID as Long

Retrieves the item menu command identifier.

TypeDescription
Long A long expression that indicates the menu command identifier.

Use the Command property of the control to get a Command object based on the item's identifier. You can use Caption property of the Item object to retrieves the items' caption. Use the Add property of the Menu object to add a new item to your context menu. Use the ID property of the Item object to change the item's identifier. It is not recommended changing the identifier at runtime. The ID should be unique, but it is not a requirement. If you have two or more items with the same identifier the Command property will get you the first command that has that identifier. The following sample shows how to get the caption of the menu item that has been selected on the popup menu:

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If (Button = 2) Then
        Dim nID As Long
        nID = PopupMenu1.ShowAtCursor
        If (nID > 0) Then
            MsgBox "You have selected the '" & PopupMenu1.Command(nID).Caption & "'"
        End If
    End If
End Sub