Solved

ComboBox Help

Posted on 2004-10-11
4
207 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now