Solved

Text command bar

Posted on 2000-04-25
1
329 Views
Last Modified: 2012-05-04
I'm trying to create a custom command bar which looks like the standard menu bar, text only, not buttons. I can build the bar but can only get buttons with text and an icon on the top level (like File  Edit  View etc.).

The code is below. LoadCustomCmdBar uses CommandsBar.Add(..msoBarTop). AddTopCmdBarCtl uses Controls.Add(msoControlPopup). And finally AddSubCmdBarCtl adds a msoControlButton.

This code creates the menu except that the top level control is a button with Roster and a down arrow. topCmdBarCtl.Style can't be used because it's a popup. When I change the top level control to msoCommandButton (to use .Style) I can't add buttons to the control.

My question is what combination of parameters creates a text type menu?

----------------------------------------------------------------------

Option Explicit
    'Definitions:
    '  customCmdBar     the new command bar, gstrCustomCmdBarName
    '       GSChapter CmdBar
    '  topCmdBarCtl a control that's always visible...main level
    '         Roster
    '  subCmdBarCtl a control that's below a top level control
    '           Export
    '           Import
    Dim cbr As CommandBar
   
Public Sub ChangeCmdBar()
    If MsgBox("Yes to load, No to unload", vbYesNo + vbDefaultButton2) = vbYes Then
        LoadCustomCmdBar
    Else
        UnloadCustomCmdBar
    End If
End Sub

Public Sub LoadCustomCmdBar()
    Dim customCmdBar As CommandBar
    Dim topCmdBarCtl As CommandBarControl
   
    For Each cbr In CommandBars
        If cbr.Name = gstrCustomCmdBarName Then
            cbr.Delete
        Else
            If cbr.Visible Then cbr.Enabled = False
        End If
    Next cbr

    Set customCmdBar = CommandBars.Add("GSChapter CmdBar", msoBarTop, False, True)
   
    Set topCmdBarCtl = AddTopCmdBarCtl(customCmdBar, "&Roster")
    AddSubCmdBarCtl topCmdBarCtl, "&Import", "cbRoster_Import"
    AddSubCmdBarCtl topCmdBarCtl, "&Export", "cbRoster_Export"
    AddSubCmdBarCtl topCmdBarCtl, "Create &floppy disks", "cbRoster_DistFloppy"
       
    customCmdBar.Visible = True
End Sub

Public Function AddTopCmdBarCtl(customCmdBar As CommandBar, _
                        theCaption As String) As CommandBarControl
    Dim topCmdBarCtl As CommandBarControl
   
    Set topCmdBarCtl = customCmdBar.Controls.Add(msoControlButton)
    topCmdBarCtl.caption = theCaption
    Set AddTopCmdBarCtl = topCmdBarCtl
End Function

Public Function AddSubCmdBarCtl(topCmdBarCtl As CommandBarControl, _
                               theCaption As String, _
                               onAction As String) As Boolean
    Dim subCmdBarCtl As CommandBarControl

    Set subCmdBarCtl = topCmdBarCtl.Controls.Add(msoControlButton)
    With subCmdBarCtl
        .Style = msoButtonCaption
        .caption = theCaption
        .onAction = onAction
        .Tag = theCaption
        .TooltipText = theCaption
    End With
End Function

Public Sub UnloadCustomCmdBar()
    For Each cbr In CommandBars
        If cbr.Name = gstrCustomCmdBarName Then cbr.Delete
    Next cbr
   
    Set cbr = CommandBars("Database")
    Set cbr = CommandBars("Visual Basic")
    cbr.Visible = True
    cbr.Enabled = True
    Set cbr = CommandBars("Menu Bar")
    cbr.Visible = True
    cbr.Enabled = True
End Sub

'*****************************************
'********** OnAction procedures **********
'*****************************************

Public Sub cbRoster_Export()
    DoCmd.OpenForm "frmExport"
End Sub

Public Sub cbRoster_Import()
    DoCmd.OpenForm "frmImport"
End Sub

Public Sub cbRoster_DistFloppy()
    MsgBox "not implemented yet"
End Sub
0
Comment
Question by:ljohnson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
mgrattan earned 150 total points
ID: 2748230
Here's a code example from the on-line help that shows how to create Text-only menu items.  The key is to use the Menubar:=True option when adding the CommandBar:

Set menubar = CommandBars.Add _
    (Name:="mBar", Position:=msoBarRight, MenuBar:=True)
With menubar
    .Protection = msoBarNoMove
    .Visible = True
End With

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question