Connecting Tech Pros Worldwide Help | Site Map

Set Toolbar Combobox items when Toolbar is called?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 12:42 PM
lauren quantrell
Guest
 
Posts: n/a
Default Set Toolbar Combobox items when Toolbar is called?

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


  #2  
Old November 13th, 2005, 12:47 PM
lauren quantrell
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.