+ Reply to Thread
Results 1 to 4 of 4

userform one combobox dependent on another

  1. #1
    Registered User
    Join Date
    07-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    7

    userform one combobox dependent on another

    I have a userform that includes 2 combo boxes (cboRoadway, cboStreet). These 2 are dependent on each other. It is comparable to a city / state drop down list.
    By selecting roadway AA, you would get a list of matching cross streets for AA.
    By selecting roadway BB, you would get a new list of matching cross streets for BB.

    cboRoadway list values are populated in my userform_initialize statement.

    Scenario: user selects a roadway, then selects a matching street. The user realizes they chose the wrong roadway, so they go back and change the roadway.
    I need the street list to clear and refresh so that they new street choices match the new roadway selection.

    I hope this makes sense. Go easy on me since I've only done a handful of my own VBA projects.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: userform one combobox dependent on another

    Do not use additem to populate a combobox or listbox

    This will be sufficient:
    Please Login or Register  to view this content.
    I suppose
    roadways in column A
    streets of first roadway in column B
    streets of second roadway in column C, etc.
    Last edited by snb; 07-06-2010 at 03:57 AM.

  3. #3
    Registered User
    Join Date
    07-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: userform one combobox dependent on another

    Quote Originally Posted by snb View Post
    Do not use additem to populate a combobox or listbox

    This will be sufficient:
    Please Login or Register  to view this content.
    I suppose
    roadways in column A
    streets of first roadway in column B
    streets of second roadway in column C, etc.
    Is there additional code I need with the above replacement? I replaced my code in cboRoadway_afterupdate with the above code. It returns the values for cboRoadway. Is there additional code I need somewhere else to make the above line work?

    Column1 - contains list of major roadways (cboRoadway) such as IH-35E, IH-635E, US-75
    Column2 - contains list of streets (cboStreet) that cross only IH-35E
    Column3 - contains list of streets (cboStreet) that cross only IH-635E
    Column4 - contains list of streets (cboStreet) that cross only US-75

    When the user selects US-75 in cboRoadway, I want only the list in Column4 to appear in the cboStreets list.

  4. #4
    Forum Contributor Gabor's Avatar
    Join Date
    02-15-2004
    Location
    Székesfehérvár, Hungary
    MS-Off Ver
    xl2016
    Posts
    226

    Re: userform one combobox dependent on another

    At initialization of the userform you get the comboboxes filled, except the cboStreet

    Please Login or Register  to view this content.
    The following fills in your comboboxes:

    Please Login or Register  to view this content.
    The following runs when user selects any out of the dropdown:

    Please Login or Register  to view this content.
    If I'm not mistaken about the request.
    Not tested.
    Regards,

    Gabor

    Protect trees.. maybe one day we need to climb back....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1