Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ComboBox Help

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

916 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