Solved

ComboBox Help

Posted on 2004-10-11
4
210 Views
Last Modified: 2010-05-02
I'm using VBA.

I'm need to add the same data in to multiply comboboxes.  I'm using the .additem method.  is there an easier way to do this.

How would i go about using an array?
0
Comment
Question by:Jason_Kha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12280110
Not sure about any other way to duplicate lists other than using AddItem(). But here is an example on how to duplicate a combo box. Same goes for other controls and the form. However, when a new combo box is duplicated from another combo box, its list will be empty.

First add a combo box to a form. Set its index property to 0. Since we want to start an array. Copy the code below.

Private Sub Command1_Click()
'Loads a new combo box in the memory. Index value will have to be one higher than the existing highest index
Load Combo1(Combo1.UBound + 1)
'Moving the combo box to a particular position on the form
Combo1(Combo1.UBound).Move Combo1.UBound * 10, Combo1.UBound * 10
'Making it visible on the form.
Combo1(Combo1.UBound).Visible = True
End Sub
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12280164
Here is a general idea of loading the combo:

'Crerate the array
Dim MyWeek
MyWeek = Array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")

'Clear the box before adding items
Form1.cmbday.Clear

'Add the new items
for x = 0 to ubound(MyWeek )
    'Add the item to the drop down
    Form1.cmbday.AddItem MyWeek (x)
next x


0
 
LVL 8

Accepted Solution

by:
ampapa earned 500 total points
ID: 12280186
Sorry about the double post I thought I would add something. In the sub below you could always just add your multiple comboboxes to fill:

'Add the new items
for x = 0 to ubound(MyWeek )
    'Add the item to the drop down
    Form1.cmbday1.AddItem MyWeek (x)
    Form1.cmbday2.AddItem MyWeek (x)
    Form1.cmbday3.AddItem MyWeek (x)
    ...
next x
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12280431
Thanks for the grade. Glad I could help.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question