Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ComboBox Help

Posted on 2004-10-11
4
Medium Priority
?
212 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 2000 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

Independent Software Vendors: 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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

722 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