Results 1 to 7 of 7
  1. #1
    dkimbrell42 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Cleveland, OH
    Posts
    4

    Popup CommandBar executing all CommandBarControl options at once

    I'm trying to create a popup command bar with a few options. I'd like to click on a command button on my form to trigger the display of the popup. The trouble is, as soon as I click on the command button, each list item's action executes, and after the actions execute, the popup menu appears but doesn't actually do anything. I'm sure I'm doing something wrong as I've never been able to get this to work since using it with the old 2003 method. Can someone help? This is the code that executes when the button is pressed (and is supposed to show the popup and let users select an option)


    Code:
        Public Function OppMenu() As Integer
        Dim oMenu As CommandBar, oItem As CommandBarControl
        Set oMenu = CommandBars.Add("", msoBarPopup, , True)
        With oMenu
            Set oItem = oMenu.Controls.Add:  oItem.Caption = "New Opportunity": oItem.OnAction = MsgBox("New") 'NewOpp("frmPopoutOpps")
            Set oItem = oMenu.Controls.Add:  oItem.Caption = "Delete Opportunity": oItem.OnAction = MsgBox("delete") 'cmdDelete("listopportunities", 1)
            Set oItem = oMenu.Controls.Add:  oItem.Caption = "Opportunity History": oItem.OnAction = ""
            Set oItem = oMenu.Controls.Add:  oItem.Caption = "Opportunity Summary": oItem.OnAction = ""
        End With
        oMenu.ShowPopup
        End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    I did some quick testing. Code adds a tab to the ribbon. Is that what you want to accomplish?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dkimbrell42 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Cleveland, OH
    Posts
    4
    Thanks for the reply. I don't intend to add a tab. I have a button on my form, and I want it so that when a user presses the button, a menu of options pops up - a popup menu. The code I included does work to show the popup menu, but it automatically executes all the "onaction" commands of the entire menu before actually showing the menu. Do you know how to make this work so that the onaction routines only run when the option they belong to is clicked on?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Got the following to work:

    Code:
    Sub CmdBar1()
        Dim oMenu As CommandBar, oItem As CommandBarControl
        Set oMenu = CommandBars.Add("", msoBarPopup, , True)
        Set oItem = oMenu.Controls.Add:  oItem.Caption = "New Opportunity": oItem.OnAction = "=MsgBox('New')"  'NewOpp("frmPopoutOpps")
        Set oItem = oMenu.Controls.Add:  oItem.Caption = "Delete Opportunity": oItem.OnAction = "=MsgBox('delete')" 'cmdDelete("listopportunities", 1)
        Set oItem = oMenu.Controls.Add:  oItem.Caption = "Opportunity History": oItem.OnAction = ""
        Set oItem = oMenu.Controls.Add:  oItem.Caption = "Opportunity Summary": oItem.OnAction = ""
        oMenu.ShowPopup
    End Sub
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    dkimbrell42 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Cleveland, OH
    Posts
    4
    This worked! Somehow while trying to build this by combining multiple snippets from various places, I ended up with a nesting With...statement which caused the problem. Thank you!

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Actually, the With End With was not the issue, really did not do anything, if it had been the only correction code still would not have worked properly. The issue was syntax of the OnAction argument. Note the parameter is within quote marks and includes an equal sign.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    dkimbrell42 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    Cleveland, OH
    Posts
    4
    I literally just figured this out as you posted it. Once I changed the dummy msgboxes back to the functions, the error reoccurred and so I did a careful comparison of your solution and found the quote and equal sign difference. Many thanks!

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

Similar Threads

  1. executing update query
    By deepucec9 in forum Queries
    Replies: 2
    Last Post: 10-27-2015, 10:02 AM
  2. Executing AT Commands thru VBA
    By rd.prasanna in forum Programming
    Replies: 4
    Last Post: 04-13-2015, 01:28 PM
  3. Need Help executing an update in form
    By ismith in forum Forms
    Replies: 17
    Last Post: 01-20-2012, 08:42 AM
  4. Executing Query to Excel?
    By objNoob in forum Programming
    Replies: 1
    Last Post: 03-17-2010, 04:59 PM
  5. How get path of executing database?
    By mscertified in forum Forms
    Replies: 3
    Last Post: 11-09-2005, 03:56 PM

Tags for this Thread

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