Combo box question

Posted on 2003-03-13
Medium Priority
Last Modified: 2010-05-01
I have 3 items in my combobox  :Banana,orange,mango
when the program run for the first time the Banana will be selected in the combobox ,now i have a listbox right below the combo, what i need the program to do is, whenener user select item from combo the content of the listbox will be cleared (here i only allow user to select existing item from combobox), thank you
Question by:indra_eva2002
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

Expert Comment

ID: 8132839
this will clear the listbox named List1

Dim i As Integer
i = List1.ListCount - 1
While i >= 0
    List1.RemoveItem i
    i = i - 1

is that what you mean?
LVL 11

Accepted Solution

supunr earned 200 total points
ID: 8132859
private sub Form_Load()
    Combo1.AddItem "Banana"
    Combo1.AddItem "Orange"
    Combo1.AddItem "Mango"
    ' Select first item
    Combo1.ListIndex = 0
    Combo1.Style = 2 ' Dropdown list
End Sub

Private Sub Combo1_Click()
    if (Combo1.Text = "Banana") then
        List1.AddItem "Banana Item1"
        List1.AddItem "Banana Item2"
        List1.AddItem "Banana Item3"
        ' etc.
    elseif (Combo1.Text = "Orange") then
        List1.AddItem "Orange Item1"
        List1.AddItem "Orange Item2"
        List1.AddItem "Orange Item3"
        ' etc.
    Elseif (Combo1.Text = "Mango") then
        List1.AddItem "Mango Item1"
        List1.AddItem "Mango Item2"
        List1.AddItem "Mango Item3"
        ' etc.
    end if
    list1.listindex = 0 ' select first item
End Sub

Good LUck!

Author Comment

ID: 8132903
Excellent, thanks SUPUNR for solving my problem.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

800 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