Break between ItemSelected from List Box

  • Thread starter Thread starter Pamela
  • Start date Start date
P

Pamela

I have a text box that takes the entries from a multi-select list box and
concatenates them. My code is not reading that there is supposed to be a
comma and space between each of the selected items from my list box. My code
currently lists them correctly but all together but running into each other
with no spaces. I believe the problem lies in line 5 where "strText" is. We
tried setting it to varRow but that just lists the # of items selected. 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 = "The vehicle sustained damage to the " & strText & ", "
Next varRow
Me.Text39 = Left(Me.Text39, Len(Me.Text39) - 1) & "."

Thank you so much!

Pamela
 
Dim varRow As Variant, strText As String

strText = vbNullString
If Me.lbDamagedParts.ItemsSelected.Count > 0 Then
For Each varRow In Me.lbDamagedParts.ItemsSelected
strText = strText & Me.lbDamagedParts.Column(0, varRow) & ", "
Next varRow
Me.Text39 = "The vehicle sustained damage to the " & _
Left(strText, Len(strText) - 2) & "."
Else
Me.Text39 = "The vehicle did not sustain any damage."
End If
 
Thank you, Thank you, Thank you! I've been struggling with this aspect for 3
days and Poof! it's fixed - and working beautifully! I really appreciate
your time and help in this and all of those out there that have spent time
helping me on this project!

Pamela
 
Hi Doug,

I was so excited when you gave me this code and it worked just perfectly. I
decided to try to make the form more user-friendly and filtered the listbox
items by another cbo on the form. I thought I had it nailed today but when I
tested it, all of a sudden, the items selected aren't showing up from your
code here. Instead, I am getting, "The vehicle sustained damage to the , , ,
, ,." Any ideas why the code that worked so beautifully before would stop
reading the variable just because the box is now filtered? And note, that it
isn't taking the "Else" case should there be no selection, so it's reading
that there is a selection and even reading the correct # of commas - but not
the text itself. Thank you so very much for any help you can give me on
this!!

Pamela
 
Did you change what order the fields are in the list box? Remember that the
code is supposed to be grabbing whatever's in the first column of each of
the selected rows.
 
When staring at your code, I remembered something I had read about the Column
function which triggered the possibility that maybe the column count had
changed. I added back the ID to the list box query and it worked again.
Thanks so much!
 
Back
Top