Results 1 to 3 of 3
  1. #1
    udigold1 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2010
    Posts
    29

    Type mismatch on right_click context menu

    Hi,

    I'm trying to add a context menu to a listbox, so I've found this code (that fires up on mouse_up event), but I always get a type mismatch on code row no.30 (Set combo = .Controls.Add(Type:=msoControlButton)
    I'm using Access 2016.
    Any suggestions how to fix it? or another alternative for a context menu?
    Thanks in advance!


    Udi

    Code:
    Public Sub SetUpContextMenu()
      ' Note: This requires a reference to Microsoft Office Object Library
    5    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
    10    On Error Resume Next
        CommandBars("MyListControlContextMenu").Delete
    15    On Error GoTo 0
        ' Make this menu a popup menu
    20    With CommandBars.Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
        ' Provide the user the ability to input text using the msoControlEdit type
    25    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
    30    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
    40    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
    50  End With
    End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    just a guess, but at first glance, you are trying to use .Controls.Add as a method of CommandBars.Add I suspect CommandBars.Add is not in the hierarchy of Controls.Add
    Maybe changing your With opener to
    With Commandbars
    then invoke .Add for the commandbar and later, .Add for the controls; i.e.
    Code:
    20    With CommandBars
      .Add(Name:="MyListControlContextMenu", Position:=msoBarPopup)
        ' Provide the user the ability to input text using the msoControlEdit type
    25    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
    30    Set combo = .Controls.Add(Type:=msoControlButton)
    etc
    I would have to find something to test that theory on
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    not having your db to play with (and the fact that my commandbar stuff is rusty) is a bit of a disadvantage, but after making several changes, I found that other types could be added, but not msoControlButton. Try anything else (e.g. msoControlDropdown) regardless if it's what you can use, just to see if you can get past the current error line as I did.
    Not sure if any of this will work anyway. If memory serves, commandbar objects could only be added to the ribbon as of 2007, so I gave up trying to control them way back when.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 10-08-2018, 10:30 AM
  2. Replies: 13
    Last Post: 10-03-2017, 04:12 PM
  3. Replies: 2
    Last Post: 03-30-2016, 08:27 PM
  4. Custom context menu limit - only one ??
    By Lukael in forum Programming
    Replies: 1
    Last Post: 02-22-2016, 03:29 AM
  5. right click context menu
    By rpeare in forum Programming
    Replies: 8
    Last Post: 10-27-2014, 11:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums