• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Add a combo box to a toolbar and reference the selection

Hi,

Is it possible to add a combo box to a custom toolbar if so how. I'll need to populate and extact the selection using VBA. I'm using Access 2003.
0
geraintcollins
Asked:
geraintcollins
  • 3
1 Solution
 
peter57rCommented:
Dim newitem As Object
Set newitem = CommandBars("prTool").Controls.Add(Type:=msoControlComboBox)
CommandBars("prTool").Controls(1).AddItem "AAAAAA"
CommandBars("prTool").Controls(1).AddItem "BBBBBB"
CommandBars("prTool").Controls(1).AddItem "CCCCCC"
0
 
peter57rCommented:
posted too early...
the code above adds a combo box with 3 options to a custom toolbar called prtool
0
 
peter57rCommented:
The only way I know to deal with the selection is to base the action on the listindex property...
Sub CBOAction()
Dim Sel As Long
Sel= CommandBars("prtool").Controls(1).ListIndex
    Select Case sel
        Case 1   'AAAAAA
            sub1
        Case 2   'BBBBBB
            sub2
        Case 3  'CCCCCC
            sub3
        Case Else
            MsgBox ("Invalid choice. Please choose again.")
    End Select
End Sub
0
 
geraintcollinsAuthor Commented:
Perfect, thanks Peter, the only thing I had to add was a reference to the microsoft office 11.0 object library as it wasn't happy with the control type.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now