Custom commandbar via VBA

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
 
Joined
Dec 31, 2016
Messages
1
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top