Connecting Tech Pros Worldwide Help | Site Map

Set Toolbar Combobox items when Toolbar is called?

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Error Messages in Access hyperpau insights 1 January 16th, 2009 03:11 PM
Adding a combobox control to a shortcut menu stinehelferw@excite.com answers 1 August 18th, 2006 03:15 PM
Error Trapping In Access 2000 Peter Frost answers 6 November 12th, 2005 11:14 PM
Error Trapping In Access 2000 Peter Frost answers 6 November 12th, 2005 10:50 PM