Adding ", " to concatenated text

P

Pamela

I have a control that is to display in the On Enter event, a concatenated
sentence including the users choices in a multi-select list box. The code is
mainly from nice people here which I've taken bits from and added to and it
almost works except for getting a comma and space between the entries. Here
is the result I'm getting:
"There is damage to A/C systemCooling systemDecklid/tailgate,."
I want it to be:
"There is damage to the A/C system, Cooling system, Decklid/tailgate."
Here is my code:
Dim varRow As Variant, strText As String
strText = vbNullString
For Each varRow In Me.lbDamagedParts.ItemsSelected
strText = strText & Me.lbDamagedParts.Column(0, varRow)
Me.Text39 = "There is damage to " & strText & ", "
Next varRow
Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "."

Thank you so much for helping me get through this!!

Pamela
 
J

John W. Vinson

I have a control that is to display in the On Enter event, a concatenated
sentence including the users choices in a multi-select list box. The code is
mainly from nice people here which I've taken bits from and added to and it
almost works except for getting a comma and space between the entries. Here
is the result I'm getting:
"There is damage to A/C systemCooling systemDecklid/tailgate,."
I want it to be:
"There is damage to the A/C system, Cooling system, Decklid/tailgate."
Here is my code:
Dim varRow As Variant, strText As String
strText = vbNullString
For Each varRow In Me.lbDamagedParts.ItemsSelected
strText = strText & Me.lbDamagedParts.Column(0, varRow)
Me.Text39 = "There is damage to " & strText & ", "
Next varRow
Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "."

Thank you so much for helping me get through this!!

Pamela

You're almost there! Append a comma and a blank for each value you append, and
then trim off the last comma at the end:

Dim varRow As Variant, strText As String
strText = vbNullString
For Each varRow In Me.lbDamagedParts.ItemsSelected
strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", "
Me.Text39 = "There is damage to " & strText & ", "
Next varRow
Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 2) & "."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top