Connecting Tech Pros Worldwide Help | Site Map

Set Toolbar Combobox items when Toolbar is called?

lauren quantrell
Guest
 
Posts: n/a
#1: Nov 13 '05
I use the following code to create a combobox in a toolbar:

'You must set a reference to the Microsoft Office x.0 Object Library to
run this code! Dim newcombo
Set newcombo =
CommandBars("MyToolbarName").Controls.Add(Type:=ms oControlComboBox)
With newcombo
.AddItem "(Prompt User)Select an Item fro the List:"
.AddItem "-----------------------------"
.AddItem "Item Three"
.AddItem "Item Four"
.AddItem "Item Five" 'and so on...
.Caption = "Some Label"
.Width = 100
.Style = msoComboLabel
.Style = msoComboNormal
.OnAction = "MyFunctionNameToCall"
.BeginGroup = True
.DropDownLines = 30
.ListIndex = 1
End With

What I'm wondering is if there is a way to populate a toolbar list box
every time a user opens the toolbar of selects the toolbar combobox. I
want the data to change in each .AddItem

Is this possible?

Thanks,
lq

lauren quantrell
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Set Toolbar Combobox items when Toolbar is called?


For anyone having a similar problem, I figured out the solution:

Function RepopulateToolbarCombo(myStoredProcedureName As String,
myToolbarName As String, myComboName As String)
On Error GoTo myErr

Dim objBar As Object, objCbo As Object
Dim RS As ADODB.Recordset
Dim myColumnName as string

myColumnName = "SomeColumnName" 'change this to the name of the
column in the stored procedure you wish to use to populate your
combobox

Set RS = CurrentProject.Connection.Execute("EXEC " &
myStoredProcedureName)

Set objBar = Application.CommandBars(myToolbarName)

Set objCbo = objBar.Controls(myComboName)

With objCbo
.Clear 'clear the old values
If Not RS.BOF And Not RS.EOF Then
Do While Not RS.EOF
.AddItem Nz(RS(myColumnName)) 'populate combobox with
each value in the stored procedure
RS.MoveNext
Loop
End If
End With

myExit:
On Error Resume Next
RS.Close
Set RS = Nothing
Set objCbo = Nothing
Set objBar = Nothing
Exit Function
myErr:
MsgBox err.number & " " & err.description
Resume myExit
End Function

Closed Thread