2013-12-12 127 views
0

我是新来这个伟大的论坛。 我正在尝试做列表框上的右键单击菜单。 目前我试图实现一个右键菜单,它将显示一个简单的信使框。弹出窗口中的右键菜单

我的问题是,列表框是在弹出窗体上打开了最大化。现在,当我右键单击列表框时,我看到了右键单击菜单,但是当我点击其中一个菜单选项时,没有任何事情发生(似乎它不会按照它应该去的功能)。我也在功能上提出了断点,但它永远不会提示。

重要的是要提到,如果我将表单弹出选项设置为无右键单击菜单完美工作(当我点击其中一个选项,我看到它的匹配邮件框)。

我运行下面的VBA代码:

这是我的列表框鼠标向上事件处理程序:

Private Sub Song_List_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 

' Call the SetUpContextMenu function to ensure it is setup with most current context 
' Note: This really only needs to be setup once for this example since nothing is 
' changed contextually here, but it could be further expanded to accomplish this 
SetUpContextMenu 
' See if the right mouse button was clicked 
If Button = acRightButton Then 
'DoCmd.CancelEvent 
CommandBars("MyListControlContextMenu").ShowPopup 
End If 
End Sub 

设立 “SetUpContextMenu” 子:

Public Sub SetUpContextMenu() 
' Note: This requires a reference to Microsoft Office Object Library 
Dim combo As CommandBarControl 

' 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 

On Error Resume Next 
CommandBars("MyListControlContextMenu").Delete 
On Error GoTo 0 

' Make this menu a popup menu 
With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup) 

' Provide the user the ability to input text using the msoControlEdit type 
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 
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 
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" 
combo.SetFocus 
combo.Visible = True 
End With 

End Sub 

设置全部3功能,点击显示不同的信箱:

Public Function getText() As String 

getText = CommandBars("MyListControlContextMenu").Controls(" Lookup Text:").Text 

' You could optionally do something with this text here, 
' such as pass it into another function ... 
MsgBox "You typed the following text into the menu: " & getText 

End Function 

Public Function LookupDetailsFunction() As String 

LookupDetailsFunction = "Hello World!" 

MsgBox LookupDetailsFunction, vbInformation, "Notice!" 

End Function 

Public Function DeleteRecordFunction() 

' If Not IsNull(Forms!MyFormName.Controls("Song_List").Colu mn(0)) Then 
MsgBox "Record Deleted" 
' End If 

End Function 

回答

0

只需将属性表(在其他选项卡中)中的快捷菜单栏设置设置为快捷菜单的名称即可。

你在那个时候不应该需要任何代码来显示/启动你创建的上下文菜单。

+0

shourtcut菜单栏设置之前已设置为“MyListControlContextMenu”。问题不在菜单中,可能存在与弹出窗体有关的限制... – skakooli2