Hello all!
This is a continuation of a previous post. I have an unbound listbox "Needs", and in the onclick event have the following code which works great if I have more than one item selected, but if I only have one item selected, it does not put it in the text box "ServiceText". Thoughts? TIA!
Code:
Private Sub Needs_BeforeUpdate(Cancel As Integer)
On Error GoTo errHandler
Dim ctl As Control
Dim strStart As String, strEnd As String
Dim aryList As String
Dim varSelected As Variant
If Me.ServiceText = "" Then
Me.ServiceText = Me.csvtext
End If
Set ctl = Me!Needs
' Me.Needs = Me.Needs.ItemData(0)
Select Case ctl.ItemsSelected.Count
Case Is = 0
MsgBox "You haven't selected anything"
Me.ServiceText = ""
Case Is = 1
aryList = ctl.Column(1, ctl.ItemsSelected(0))
Case Is > 1
For Each varSelected In ctl.ItemsSelected
aryList = aryList & ctl.Column(1, varSelected) & ", "
Next varSelected
aryList = Left(aryList, Len(aryList) - 2)
strStart = Left(aryList, InStrRev(aryList, ",") - 1)
strEnd = Mid(aryList, InStrRev(aryList, ",") + 2)
aryList = strStart & " and " & strEnd
Me.ServiceText = aryList
End Select
Exit Sub
errHandler:
MsgBox "Error " & Err.Number & ": " & Err.Description & " in " & _
VBE.ActiveCodePane.CodeModule, vbOKOnly, "Error"
End Sub