Changing combo box list based on another combo box selection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • troy_lee@comcast.net

    Changing combo box list based on another combo box selection

    I have a continuous form that has one combo box (cbo1) with the
    selectable values of "Removal" and "Installati on". I would like to
    change another combo box (cbo2) value list based on the selection in
    cbo1.

    For example, when the user selects "Removal" from cbo1 I would like
    the value list of cbo2 to be one set of values and when "Installati on"
    is selected in cbo1 I would like the value list of cbo2 to be a
    different set of values.

    Is this possible?

    Thanks in advance.

    Troy Lee
  • Salad

    #2
    Re: Changing combo box list based on another combo box selection

    troy_lee@comcas t.net wrote:
    I have a continuous form that has one combo box (cbo1) with the
    selectable values of "Removal" and "Installati on". I would like to
    change another combo box (cbo2) value list based on the selection in
    cbo1.
    >
    For example, when the user selects "Removal" from cbo1 I would like
    the value list of cbo2 to be one set of values and when "Installati on"
    is selected in cbo1 I would like the value list of cbo2 to be a
    different set of values.
    >
    Is this possible?
    >
    Thanks in advance.
    >
    Troy Lee
    Sometimes cbo2's rowsoure might be
    "Select fld from table where id = " & cbo1
    In this case, in the AfterUpdate event of cbo1 you'd enter
    Me.cbo2.Requery

    You might have to change the rowsource in other cases
    If me.cbo1 = "Install" then
    Me.cbo2.rowsour ce = "Select fld from table1"
    Else
    Me.cbo2.rowsour ce = "Select fld from table2"
    Endif

    Shark Surfer


    Comment

    • troy_lee@comcast.net

      #3
      Re: Changing combo box list based on another combo box selection

      On May 22, 10:14 am, Salad <o...@vinegar.c omwrote:
      troy_...@comcas t.net wrote:
      I have a continuous form that has one combo box (cbo1) with the
      selectable values of "Removal" and "Installati on". I would like to
      change another combo box (cbo2) value list based on the selection in
      cbo1.
      >
      For example, when the user selects "Removal" from cbo1 I would like
      the value list of cbo2 to be one set of values and when "Installati on"
      is selected in cbo1 I would like the value list of cbo2 to be a
      different set of values.
      >
      Is this possible?
      >
      Thanks in advance.
      >
      Troy Lee
      >
      Sometimes cbo2's rowsoure might be
      "Select fld from table where id = " & cbo1
      In this case, in the AfterUpdate event of cbo1 you'd enter
      Me.cbo2.Requery
      >
      You might have to change the rowsource in other cases
      If me.cbo1 = "Install" then
      Me.cbo2.rowsour ce = "Select fld from table1"
      Else
      Me.cbo2.rowsour ce = "Select fld from table2"
      Endif
      >
      Shark Surferhttp://www.youtube.com/watch?v=6zc79UQ j1hQ
      Salad,
      Thanks for the input. Why the ambiguity? You say sometimes it might
      require a requery and others I may have to use an If...Then statement.
      Which method is best in your opinion?

      Thanks.

      Troy

      Comment

      • CenturionX

        #4
        Re: Changing combo box list based on another combo box selection

        Hello,

        When you are changing the values of a combobox, you have to know how
        to fill it in

        - Inserting a list of values (manualy):
        You have to set the RowSourceType first to "Value List", then insert
        the values
        Me.MyCombo.RowS ourceType = "Value List"
        Me.MyCombo.RowS ource = "Item; Item2; Item3"

        - Using a query (automatically) :
        You have to set the RowSourceType first to "Value List", then insert
        the values
        Me.MyCombo.RowS ourceType = "Table/Query"
        Me.MyCombo.RowS ource = "SELECT Id FROM Customers" or
        Me.MyCombo.RowS ource = rsReg where rsReg is a recorsdet

        Nice coding.

        Comment

        • CenturionX

          #5
          Re: Changing combo box list based on another combo box selection

          You could use too the Click event of the Combobox_1, so everytime you
          pick an item the events trigers and you could profit to change the
          combobox_2

          Private Sub Combobox1_Click ()
          if me.Combobox1.va lue = ucase("install" ) then

          me.Combobox2.ro wsource = "Item1; Item2" 'Presetting RowSource
          = "Value List"
          or
          me.Combobox2.ro wsource = "SELECT ..." 'Presetting RowSource =
          "Table/Query"
          or
          me.Combobox2.ro wsource = rsRecordset 'Presetting RowSource =
          "Table/Query"

          else
          ...
          endif

          :-)

          End Sub

          Comment

          • troy_lee@comcast.net

            #6
            Re: Changing combo box list based on another combo box selection

            Nice work guys. I combined the suggestions of you both and it works
            beautifully. Thanks for the great input.

            BTW, for anyone else interested, this is the code for the solution.

            In the After_Update Event of cbo1:

            Private Sub cboReworkActivi ty_AfterUpdate( )

            If Me.cboReworkAct ivity = "Removal" Then
            Me.txtNewXmtrSt atus.RowSourceT ype = "Value List"
            Me.txtNewXmtrSt atus.RowSource = "In Cleanroom; Out of
            Cleanroom"
            Else
            Me.txtNewXmtrSt atus.RowSourceT ype = "Value List"
            Me.txtNewXmtrSt atus.RowSource = "New Xmtr.; Stock Xmtr.;
            Original Reworked Xmtr."
            End If

            End Sub

            (Note that txtNewXmtrStatu s is really a combo box.)

            Comment

            • paii, Ron

              #7
              Re: Changing combo box list based on another combo box selection

              A usability suggestion would be to disable the 2nd combo box until something
              is selected from the 1st.

              <troy_lee@comca st.netwrote in message
              news:630e4fd2-41ba-43ae-afe4-466af71a585a@27 g2000hsf.google groups.com...
              Nice work guys. I combined the suggestions of you both and it works
              beautifully. Thanks for the great input.
              >
              BTW, for anyone else interested, this is the code for the solution.
              >
              In the After_Update Event of cbo1:
              >
              Private Sub cboReworkActivi ty_AfterUpdate( )
              >
              If Me.cboReworkAct ivity = "Removal" Then
              Me.txtNewXmtrSt atus.RowSourceT ype = "Value List"
              Me.txtNewXmtrSt atus.RowSource = "In Cleanroom; Out of
              Cleanroom"
              Else
              Me.txtNewXmtrSt atus.RowSourceT ype = "Value List"
              Me.txtNewXmtrSt atus.RowSource = "New Xmtr.; Stock Xmtr.;
              Original Reworked Xmtr."
              End If
              >
              End Sub
              >
              (Note that txtNewXmtrStatu s is really a combo box.)

              Comment

              Working...