Combo Box Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmne05974
    New Member
    • Oct 2008
    • 5

    Combo Box Help

    Hoping someone can help me. I have 3 combo boxes on a form (cbobenefit1, cbobenefit2, cbobenefit3) each populated from the same field in a table. Initially only one combobox is diplayed in the form, when this is updated a second combobox appears with the same list to choose a second benefit and then a third. I have this working using the following code in the after update event of each of the comboboxes:

    Private Sub benefit1_AfterU pdate()

    Form_NewPack!be nefit2.Visible = True
    Form_NewPack!La bel56.Visible = True
    Form_NewPack.Re query

    End Sub

    Now my problem starts. I would like to concantenate each text string selected in the comboboxes with commas to separate the choices and store them in a field in a table ( tblcustomer.[benefit]). Can anyone point me in the right direction to do this. I thought about writing the values to a text box and then to the table but not sure how to go about it.

    Many thanks
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You only need one combobox to accomplish this this. Then write the values to a textbox that is bound to the field in your underlying table:
    Code:
    Private Sub YourComboBox_AfterUpdate()
      If IsNull(Me.TextBox) Then
        Me.TextBox = Me.YourComboBox
      Else
        Me.TextBox = Me.TextBox & ", " & Me.YourComboBox
      End If
     End Sub
    replacing the names TextBox and YourCombobox with your actual names.

    You could use a multi-select ListBox, with different code to do this, but a ListBox does take up a great deal more space on a form. Also, it generally is not a good idea to hold more than one piece of data in a given field, but that's really up to you. As in most rules, there are valid exceptions.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • dmne05974
      New Member
      • Oct 2008
      • 5

      #3
      Thanks Missinglinq,


      Worked a treat, made a couple of little changes as my customer wanted 3 pop up combos that apear as needed, but this one was driving me mad, you know what its like when yoou can't see for looking!

      Thanks again

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        Glad we could help!

        Linq ;0)>

        Comment

        Working...