Results 1 to 8 of 8
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097

    Office.CommandBar not taking affect

    The CommandBar below isn't taking affect after being compiled and referenced as such in my form's shortcut properties. What I get instead is the default "Cut", "Copy", "Paste" menu. The code is copied from another form I have in another app which works fine, only the "Delete Subscriber" and "Send Today's Menu" options having been added. Since I haven't had an occasion for a shortcut menu for quite awhile, I'm suspecting that I've simply forgotten something. Record Selectors are enabled on the form. The code has been executed. The form has the shortcut menu property set to YES and the name of the Bar selected from the collection's dropdown.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Public Sub RC14ClickCmdBar()
    
    
        Dim Bar As Office.CommandBar
            On Error Resume Next
            CommandBars("R-ClickReg").Delete
            On Error GoTo 0
        
        Set Bar = ResetCustomBar("R-ClickReg")
        
        With Bar.Controls.Add(msoControlButton)
            .Caption = "Cancel"
            .OnAction = "=Cancel(0)"
        End With
        
        With Bar.Controls.Add(msoControlButton)
            .Caption = "Delete Subscriber"
            .OnAction = "=xfrDelReg(0)"
        End With
            
        With Bar.Controls.Add(msoControlButton)
            .Caption = "Send Today's Menu"
            .OnAction = "=xfrDailyMenu(0)"
        End With
        
        With Bar.Controls.Add(msoControlButton)
            .BeginGroup = True
            .Caption = "SELECT ALL"
            .OnAction = "=SelectAll(0)"
        End With
    
    
        With Bar.Controls.Add(msoControlButton)
            .Caption = "Clear ALL Selections"
            .OnAction = "=ClearSelects(0)"
        End With
    
    
    '    Debug.Print "Command bar "; Bar.Name; " updated"
    
    
    End Sub
    
    
    Private Function ResetCustomBar(BarName As String) As Office.CommandBar
        On Error Resume Next
        'Delete bar if it exists
        CommandBars(BarName).Delete
        On Error GoTo 0
        
        Set ResetCustomBar = CommandBars.Add(BarName, msoBarPopup, False)
        
    End Function
    
    
    
    
    Public Function Cancel(dummy As Integer)
    
    
    End Function
    
    
    Public Function xfrDelSub(dummy As Integer)
    Call Forms("frmSubscribers").DelSub(0)
    End Function
    
    
    
    
    Public Function xfrDailyMenu(dummy As Integer)
    Call Forms("frmSubscribers").DailyMenu(0)
    End Function
    
    
    Public Function SelectAll(dummy As Integer)
    CurrentDb.Execute "UPDATE tblSubscribers SET Selected = '" & ChrW(9658) & "'"
    Forms!frmSubscribers.Form.Requery
    End Function
    
    
    Public Function ClearSelects(dummy As Integer)
    CurrentDb.Execute "UPDATE tblSubscribers SET Selected = ' '"
    Forms!frmSubscribers.Form.Requery
    End Function


  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    i think you need to call public sub RC14ClickCmdBar first.
    but why are you re-creating the shortcut menu everytime?

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    RC14ClickCmdBar is only executed once in process of creating the CommandBar. I don't even bother with calling it per-se', I just run the sub with Debug Run to cursor.

  4. #4
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    did you try to set the Form frmSubscribers shortcutmenu to R-ClickReg?
    Click image for larger version. 

Name:	prop1.png 
Views:	10 
Size:	16.9 KB 
ID:	52938

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    From my OP
    The form has the shortcut menu property set to YES and the name of the Bar selected from the collection's dropdown.

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    434
    well, I can't replicate your problem.
    Click image for larger version. 

Name:	Screenshot 2025-04-08 124317.png 
Views:	10 
Size:	13.7 KB 
ID:	52939

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Works for me also?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,097
    I found it! The old app had two versions of frmSubscribers, "frmSubscribers" and "frmSubscribers0". Apparantly, the latter had some value when the app was originally being developed?? Anyway, the Switchboard was pointing to the "0" version and all my updates were being applied to what was the originally intended form. I cleaned up the mess.

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

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2020, 02:09 PM
  2. Cannot Dim object as commandBar
    By klnlsu in forum Programming
    Replies: 4
    Last Post: 01-25-2018, 11:01 AM
  3. Replies: 6
    Last Post: 09-06-2017, 10:31 AM
  4. Replies: 3
    Last Post: 05-08-2017, 12:44 AM
  5. Replies: 4
    Last Post: 08-19-2014, 12:20 PM

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