Solved Need Code To Place Combo Data Into Text Box One After Another

Ashfaque

Search Beautiful Girls from your town for night
Local time
Tomorrow, 01:48
Joined
Sep 6, 2004
Messages
897
I am looking for a tricky code to move data from a combo after update one by one and place into a text box keeping ; (semicolon) between new and previously transferred record in text box


Example. Combo1 holding following values:

Printer
Pc
Cartridge
Monitor
Keyboard
Mouse

When I select from combo any of the above, it should add in text box and when I selects second value second time from same combo, it should keep the firstly transferred value in text box as it and add ; or , and place next value that selected from combo and so on.

Like follows:

Monitor, Keyboard, Pc, Printer

OR in following form:

Monitor;
Keyboard;
Pc;
Printer

Can someone help me
 
Have you tried?

Me.TextboxName = Me.TextboxName & ";" & Me.ComboboxName
 
replace Combo0 and Text0 with the name of your controls.
Code:
Private Sub Combo0_AfterUpdate()
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If InStr(1, strText, Me.Combo0) < 1 Then
        strText = strText & ";" & Me.Combo0 & ";"
    End If
    If Left$(strText, 1) = ";" Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = ";" Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
 
Pat, basically the data which I need to store in a text box is an work requirement in detail actually. And as per client, we need to specifically mention work altogether in one box. Otherwize you are correct, we should prepare a table and add each item in it. Thanks for advice but is an requirement.
 
replace Combo0 and Text0 with the name of your controls.
Code:
Private Sub Combo0_AfterUpdate()
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If InStr(1, strText, Me.Combo0) < 1 Then
        strText = strText & ";" & Me.Combo0 & ";"
    End If
    If Left$(strText, 1) = ";" Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = ";" Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
Looks ok but let me implement and I will let you know....Thanks Arnel for your help...
 
replace Combo0 and Text0 with the name of your controls.
Code:
Private Sub Combo0_AfterUpdate()
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If InStr(1, strText, Me.Combo0) < 1 Then
        strText = strText & ";" & Me.Combo0 & ";"
    End If
    If Left$(strText, 1) = ";" Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = ";" Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
Working good.

How about if need one below one...I tried to modify your code removing ";" with vbcr but not worked.
 
change ";" to vbNewLine

Code:
Private Sub Combo0_AfterUpdate()
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If InStr(1, strText, Me.Combo0) < 1 Then
        strText = strText & Me.Combo0 & vbNewLine
    End If
    strText = Replace$(strText, vbNewLine + vbNewLine, vbNewLine)
    If Left$(strText, 1) = vbNewLine Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = vbNewLine Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
 
Thanks Arnel,

I tried to further to add code to make a sequence numbers like 1)... 2).... before each data gets in to text box but it is wearied. I add one counter as follows

Dim MyCounter As Integer
MyCounter = MyCounter + 1

But after which line it has to set is confusing me..
I want the data to appear in below way...

1. fsdfdsaf
2. fsdfsdf
3. fsdfsd

Can you please help...
 
Code:
Private Sub Combo0_AfterUpdate()
Dim strText As String, iLine As Integer
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If InStr(1, strText, Me.Combo0) < 1 Then
        iLine = iLine + 1
        strText = strText & iLine & ". " & Me.Combo0 & vbNewLine
    End If
    strText = Replace$(strText, vbNewLine + vbNewLine, vbNewLine)
    If Left$(strText, 1) = vbNewLine Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = vbNewLine Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
 
It produces like :)

1. fdsfds
1. fdsfds
1. jgfggdsf
 
here test it again:
Code:
Private Sub Combo0_AfterUpdate()
Static iLine As Integer
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If Len(strText) =  0 Then
        iLine = 0
    End If
    If InStr(1, strText, Me.Combo0) < 1 Then
        iLine = iLine + 1
        strText = strText & iLine & ". " & Me.Combo0 & vbNewLine
    End If
    strText = Replace$(strText, vbNewLine + vbNewLine, vbNewLine)
    If Left$(strText, 1) = vbNewLine Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = vbNewLine Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
 
here test it again:
Code:
Private Sub Combo0_AfterUpdate()
Static iLine As Integer
Dim strText As String
If Me.Combo0.ListIndex <> -1 Then
    strText = Me.Text2 & ""
    If Len(strText) =  0 Then
        iLine = 0
    End If
    If InStr(1, strText, Me.Combo0) < 1 Then
        iLine = iLine + 1
        strText = strText & iLine & ". " & Me.Combo0 & vbNewLine
    End If
    strText = Replace$(strText, vbNewLine + vbNewLine, vbNewLine)
    If Left$(strText, 1) = vbNewLine Then strText = Mid$(strText, 2)
    If Right$(strText, 1) = vbNewLine Then strText = Left$(strText, Len(strText) - 1)
    Me.Text2 = strText
End If
End Sub
Wonderful....

Thanks Arnel....
Appreciate your help...
 

Users who are viewing this thread

Back
Top Bottom