Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
9 years ago

Filter UserForm ComboBox based on previous ComboBox selection

Hi… I have question regarding the use of ComboBoxes on a UserForm in a Keyword test. I have a “Department” ComboBox that is populated with the following…  “Dariy”, “Frozen”, “Grocery”…etc.  I would ...
  • TanyaYatskovska's avatar
    TanyaYatskovska
    9 years ago

    Add the Clear method at the beginning of the OnChange event handler to clear the list of Warehouse combobox. Here is my code:

    function UserForm1_cxComboBox2_OnChange(Sender)
    {
      UserForms.UserForm1.cxComboBox1.Properties.Items.Clear();
      if (UserForms.UserForm1.cxComboBox2.Text == "Frozen")
       {   
          with (UserForms.UserForm1.cxComboBox1.Properties.Items)
        {
          Add("100-Warehouse 100");
          Add("200-Warehouse 200");
        }
        }
      if (UserForms.UserForm1.cxComboBox2.Text == "Dairy")
       {   
          with (UserForms.UserForm1.cxComboBox1.Properties.Items)
        {
          Add("110-Warehouse 110");
          Add("210-Warehouse 210");
        }
        }
    }
    

    Does it help?