Solved

Text command bar

Posted on 2000-04-25
1
319 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now