Custom commandbar via VBA

  • Thread starter Thread starter Dale Fye
  • Start date Start date
D

Dale Fye

Access 2003 (SP2)

I'm working on creating some custom commandbars using VBA (I had to do this
recently while working in Excel because I could not figure out how to create
the toolbar as a popup using the View - Toolbars - Customize dialog box).

I like this method as it provides more flexibility (create my own menu
items, including dropdown and textbox), and the ability to easily copy the
code from one application to another. Plus, the code sits in a module rather
than in the command bars collection.

You have to have a reference to the Office 12 Object Library for this to
work, but I'm working on modifications for late binding. I've created a test
popup menu that I'm currently testing by calling it in the Immediate window:

Call ArcCheckMenu
commandbars("CheckMenu").ShowPopup

When I show this popup menu, and click on the dropdown item, the items in
the list show up to the right of the combo box rather than directly below it.
Does anyone have any idea why, or how to resolve this?

Public Sub ArcCheckMenu()

Dim cbr As CommandBar

Dim cbrCombo As CommandBarComboBox
Dim cbrEdit As CommandBarControl
Dim cbrButton As CommandBarButton

On Error Resume Next
CommandBars("CheckMenu").Delete
On Error GoTo ArcCheckError

Set cbr = CommandBars.Add("CheckMenu", msoBarPopup, , True)

With cbr
Set cbrCombo = cbr.Controls.Add(msoControlComboBox, , , , True)
With cbrCombo
.AddItem "2 Nodes"
.AddItem "3 Nodes"
.DropDownWidth = 70
.Caption = "Circular Reference"
'.OnAction = "=fnCircularRef()"
.Tag = .Caption
End With

Set cbrEdit = cbr.Controls.Add(msoControlEdit, , , , True)
With cbrEdit
.Width = 50
.Text = "Now is the time"
.Caption = "test"
'.OnAction = "fnDoSomething()
.Tag = .Caption
End With

End With

Exit Sub

ArcCheckError:

Debug.Print "ArcCheckMenu" & vbCrLf & Err.Number & vbCrLf &
Err.Description
Resume Next

End Sub
 
Dale,
Were you able to find a work around for the issue described in this post? I would like to be able to have a ComboBox in a Popup Menu as well.

Rex
 
Back
Top