Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5973029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:44:33+00:00 2026-05-22T20:44:33+00:00

The goal is to create menus which can be utilized with certain controls on

  • 0

The goal is to create menus which can be utilized with certain controls on an MS Access form and to be able to right click on a that control, for example on a listbox and a relevant context specific menu popup with options, which if clicked, would trigger a predefined subroutine or function.

What is the best method to accomplish this programmatically?

I am using MS Access 2003 and would like to do this using VBA.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:44:33+00:00Added an answer on May 22, 2026 at 8:44 pm

    First create an _MouseUp event to execute on the respective control looking to see if the right mouse button was clicked and if so, call the .ShowPopup method.

    Of course this assumes the

    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
    

    Since at this point the Command Bar MyListControlContextMenu is undefined, I define the Menu in a separate module as follows:

    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 
    

    Since three function have been referenced, we can move on to define these as follows-

    getText: Note, this option requires a reference to both the name of the Command Bar menu name as well as the name of the control caption.

    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: For this example, I will create a shell function and return the text “Hello World!”.

    Public Function LookupDetailsFunction() As String
    
       LookupDetailsFunction = "Hello World!"
    
       MsgBox LookupDetailsFunction, vbInformation, "Notice!"
    
    End Function
    

    DeleteRecordFunction: For this example, I will ensure the control is still valid by checking it against null, and if still valid, will execute a query to remove the record from a table.

    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
    

    Note: For LookupDetailsFunction, DeleteRecordFunction and getText functions, these must be within a public scope to work correctly.

    Finally, the last step is to test the menu. To do this, open the form, right click on the list control and select one of the options from the popup menu.

    Optionally button.FaceID can be utilized to indicate a known office icon to associate with each instance of the menu popup control.

    I found Pillai Shyam’s work on creating a FaceID Browser Add-In to be very helpful.

    References:
    Microsoft
    FaceID

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to create a trait that a case class can extend, which
My goal is to create an eBook that I can read with the Mobipocket
My goal is to create a map of maps so that I can retrieve
High Level Goal: Create a single Maven Web Application project that can be used
My goal is to create a custom TextBlock control that has a new dependency
The goal: To create a .NET dll i can reference from inside SQL Server
The goal is to create a mock class which behaves like a db resultset.
Goal: create webservice that will query database and return rows, then pass it to
My goal is to create a Web Service client that runs in a standalone
My goal is to create a reusable Attached Behavior for a FlowDocumentScrollViewer, so that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.