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
shourtcut菜單欄設置之前已設置爲「MyListControlContextMenu」。問題不在菜單中,可能存在與彈出窗體有關的限制... – skakooli2