Combobox selection changes, selected value to be appended in textbox

  • I have certain values in combobox and when I change the values, the value that I have selected should be populated in the textbox after a certain word. The code I have written keeps appending the combobox selected values instead of clearing and just populating the newly selected value. Please help.


    Private Sub cboTrial_Change()
    Dim Searchthis As String Dim StartTxt, MidTxt, EndTxt As String
    Dim index As Integer


    StartTxt = VBA.vbNullString
    MidTxt = VBA.vbNullString
    EndTxt = VBA.vbNullString


    Cells(1, 5).Value = cboTrial.Value


    If Me. cboTrial.Enabled = VBA.vbTrue Then
    If Me. cboTrial.Value <> VBA.vbNullString Then
    Call FlagControl(cboTrial, VBA.vbFalse)
    End If


    Searchthis = "by"
    index = InStr(1, txt, Searchthis) + 2


    If index > 0 Then


    StartTxt = mid(txt, 1, index)


    MidTxt = Me. cboTrial.Value


    EndTxt = mid(txt, index, Len(txt))


    txt= StartTxt & MidTxt & EndTxt


    End If
    End If


    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!