Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Thanked 0 Times in 0 Posts

    Check marks in Menu Bar

    Is there a way to have a menu bar option that, when clicked, toggles a
    check mark next to it? Alternatively, is it possible to have a set of
    options that toggle each other, similar to the Database options Large
    Icons, Small Icons, List and Details? I have a menu bar with options to
    print various reports and I want the user to be able to toggle Print
    Preview on and off in that menu bar.


  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Check marks in Menu Bar

    How about adding a combobox to a menubar? That way, the selection made would always be the one that shows on the menubar.

    Here's some sample code that adds a combobox to a commandbar called TestMenu. Just create a custom commandbar and name it TestMenu. Then run this function to add a combobox to it and populate the combobox. It will automatically set the OnAction property of the combobox to the cbEvalCombo function. This is just to give you an idea of how it would work. Oh, you need a reference to the Office object library to get at the commandbar objects through code.

    Public Function AddCombobox2Commandbar()
    Dim cbo As CommandBarComboBox
    Dim cbar As CommandBar

    Set cbar = CommandBars.Item("TestMenu")
    Set cbo = cbar.Controls.Add(msoControlComboBox)
    With cbo
    .Caption = "cboList" 'this sets the name as well
    .AddItem Text:="First Item", Index:=1
    .AddItem Text:="Second Item", Index:=2
    .DropDownLines = 3
    .DropDownWidth = 75
    .ListHeaderCount = 0
    .ListIndex = 1 'this sets the first item as the default
    .OnAction = "=cbEvalCombo('" & & "', '" & .Caption & "')"
    End With
    Set cbo = Nothing
    Set cbar = Nothing
    End Function

    Public Function cbEvalCombo(ByVal strMenuName As String, _
    ByVal strCBOName As String)
    Dim cbo As CommandBarComboBox
    Dim cbr As CommandBar

    Set cbr = CommandBars(strMenuName)
    Set cbo = cbr.Controls(strCBOName)
    Select Case cbo.ListIndex
    Case 1
    MsgBox "Woo Hoo"
    Case 2
    MsgBox "Waah hah hah hah hah hah"
    End Select
    Set cbo = Nothing
    Set cbr = Nothing
    End Function

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Indianapolis, Indiana, USA
    Thanked 0 Times in 0 Posts

    Re: Check marks in Menu Bar

    I just discovered this function while browsing the code librarian (that comes with MOD 2000). I haven't had a chance to test this yet, but it looks like it will do the trick. It appears that the menu item MUST be a command button rather than just menu text. Here is is:

    ' Checks or Unchecks a menu item depending on value of
    ' boolCheckIt argument. Set it to True to check, False to uncheck,
    ' and leave out to toggle.
    ' NOTE: There is no way to programmatically add a checkmark next to a
    ' built-in menu item; you can add checkmarks only to custom items.
    ' Checkmarks for built-in menu items are controlled by the parent
    ' application, and your code will result in the error:
    ' "Method 'State' of Object 'CommandBarButton' Failed"
    ' Calling convention:
    ' CheckMenuItem "MyCommandBar", "MyMenu", "MyMenuCommand"
    ' CheckMenuItem "MyCommandBar", "MyMenu", "MyMenuCommand", True
    ' CheckMenuItem "MyCommandBar", "MyMenu", "MyMenuCommand", False
    Dim cmdMyMenuCmd As CommandBarControl
    On Error GoTo errCheckMenuItem

    Set cmdMyMenuCmd = CommandBars(strMyMenuBar).Controls(strMyMenu).Cont rols(strMyMenuCmd)

    ' Verify this is a button control.
    If cmdMyMenuCmd.Type <> msoControlButton Then
    MsgBox "The command bar control must be of type msoControlButton."
    Exit Sub
    End If

    If IsMissing(boolCheckIt) Then 'Optional arg missing, so toggle.
    cmdMyMenuCmd.State = Not cmdMyMenuCmd.State
    Else ' Check or uncheck depending on value of boolCheckIt.
    cmdMyMenuCmd.State = boolCheckIt
    End If

    Exit Sub

    MsgBox Error$
    Resume exitCheckMenuItem
    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts