Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
How can I modify the code below to return the listbox value and not the position number of the selected value. Ex: if the value selected in the listbox is "Apples" and "Oranges" their positions are (0) and (3), the code below would show the numbers "0 , 3" but I need it to show the word "Apples, Oranges" instead and NOT the number "0, 3" Is this possible? I hope my explanation make sense. Thank you.
VBA Code:
Function lbxRPItems() As String
'Returns a list of items in the listbox
Dim lstbx As ListBox
Dim lngItems As Long
Dim lngItem As Long
Dim strReturns As String
strReturns = ""
Set lstbx = Me!lstResponsiblePerson
lngItems = lstbx.ItemsSelected.Count
If lngItems > 0 Then
For lngItem = 0 To lngItems - 1
If lngItem = 0 Then
strReturns = CStr(lstbx.ItemsSelected(lngItem))
Else
strReturns = strReturns & "," & CStr(lstbx.ItemsSelected(lngItem))
End If
Next
End If
Set lstbx = Nothing
lbxRPItems = strReturns
End Function
VBA Code:
Private Sub lstResponsiblePerson_AfterUpdate()
Dim strItems As String
strItems = lbxRPItems()
Me!lstResponsiblePerson.Value = strItems
MsgBox Me!lstResponsiblePerson
End Sub