473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

Nov 13 '05 #1
1 2067
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

Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tark Siala | last post by:
hi in VB6 (Listbox and Combobox) have nice Properties called (Item Data) when i go to VB.NET i can't Find this Properties :( please help me , i want Save tow value in one item in ComboBox 1 -...
1
by: Lauren Quantrell | last post by:
Is there a way to determine the value of a combobox that resides in a toolbar other than using CommandBars.ActionControl? I want a user to be able to change the combobox and be able to refer to the...
9
by: Scott Johnson | last post by:
Hi! I have 2 items that I need to show in a ComboBox in VB.NET (CF) called ExpenseCode and Expense Description. I only want to show the user the ExpenseDescription in the dropdown ComboBox but...
4
by: Rob Kroese | last post by:
I've got a form with a datagrid that displays a list of items, along with several textboxes, comboboxes, etc., that display the details for the selected item. The columns in the datagrid and the...
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
1
by: mookid8000 | last post by:
Hello again, group! Can someone tell me a nice way to include a zoom percentage combobox in a toolbar? My first try was a workaround, where I inserted a bunch of separators where I wanted the...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
6
by: active | last post by:
I need a combobox where the items are typed as string - not object. And another where the items are from a class I generated. Can one make such comboboxes from System.Windows.Forms.ComboBox?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.