सबसे पहले संबंधित सह पर अमल करने के लिए एक _MouseUp
घटना बनाने ntrol यह देखने के लिए देख रहा है कि सही माउस बटन क्लिक किया गया था और यदि ऐसा है, तो .ShowPopup
विधि पर कॉल करें।
बेशक यह मान लिया गया है
Private Sub MyListControlName_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Long, ByVal Y As Long)
' 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
CommandBars("MyListControlContextMenu").ShowPopup
End If
End Sub
के बाद से इस बिंदु कमान बार MyListControlContextMenu
अपरिभाषित है पर, मैं मेनू एक अलग मॉड्यूल में इस प्रकार निर्धारित करें:
Public Sub SetUpContextMenu()
' Note: This requires a reference to Microsoft Office Object Library
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
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
End With
End Sub
तीन के बाद से समारोह किया गया है संदर्भित, हम इन्हें निम्नानुसार परिभाषित करने के लिए आगे बढ़ सकते हैं-
getText: नोट, यह विकल्प के नाम दोनों के लिए संदर्भ की आवश्यकता है कमांड बार मेनू नाम साथ ही नियंत्रण कैप्शन का नाम।
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
LookupDetailsFunction: इस उदाहरण के लिए, मैं एक खोल समारोह बना सकते हैं और पाठ वापस आ जाएगी "नमस्ते दुनिया!"।
Public Function LookupDetailsFunction() As String
LookupDetailsFunction = "Hello World!"
MsgBox LookupDetailsFunction, vbInformation, "Notice!"
End Function
DeleteRecordFunction: इस उदाहरण के लिए, मैं नियंत्रण सुनिश्चित करेगा अभी भी अशक्त के खिलाफ चेक करके उसे वैध है, और यदि अभी भी मान्य, एक प्रश्न निष्पादित करेंगे एक मेज से रिकॉर्ड हटाने के लिए।
Public Function DeleteRecordFunction() As String
If Not IsNull(Forms!MyFormName.Controls("MyListControlName").Column(0)) Then
Currentdb.Execute _
"DELETE * FROM [MyTableName] " & _
"WHERE MyKey = " & Forms!MyFormName.Controls("MyListControlName").Column(0) & ";"
MsgBox "Record Deleted", vbInformation, "Notice!"
End If
End Function
नोट: LookupDetailsFunction
, DeleteRecordFunction
और getText
कार्यों के लिए, इन के भीतर एक सार्वजनिक दायरे सही ढंग से काम करने के लिए किया जाना चाहिए।
अंत में, अंतिम चरण मेनू का परीक्षण करना है। ऐसा करने के लिए, फॉर्म खोलें, सूची नियंत्रण पर राइट क्लिक करें और पॉपअप मेनू से विकल्पों में से एक का चयन करें।
वैकल्पिक रूप से button.FaceID
का उपयोग मेनू पॉपअप नियंत्रण के प्रत्येक उदाहरण के साथ संबद्ध करने के लिए ज्ञात कार्यालय आइकन इंगित करने के लिए किया जा सकता है।
मुझे एक फेसआईड ब्राउज़र ऐड-इन बनाने में बहुत उपयोगी होने के लिए Pillai Shyam's work मिला।
संदर्भ: Microsoft FaceID
जवाब पहुंच के संस्करण के बहुत निर्भर करता है। यदि ए2007, एक उत्तर, कोई पिछले संस्करण, एक पूरी तरह से अलग जवाब। –