Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
On my form, I have a listbox that returns a list of selected items from a listbox. strReturns equals the selected items position in the listbox, and strReturn equals the selected .itemdata(). The error occurs on the line of code below. Thank you.
VBA Code:
strReturn = strReturns & ", " & lstBx.ItemData(strReturns)
VBA Code:
Function lbxRPItems() As String
'Returns a list of items in the listbox
Dim lstBx As ListBox
Dim lngItems, lngItem As Long
Dim strReturns, strReturn As String
Dim varItem As Variant
strReturn = ""
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))
strReturn = lstBx.ItemData(strReturns)
Else
strReturns = strReturns & ", " & CStr(lstBx.ItemsSelected(lngItem))
strReturn = strReturns & ", " & lstBx.ItemData(strReturns)
End If
Next
MsgBox strReturn 'Test purposes to view output
End If
Set lstBx = Nothing
lbxRPItems = strReturn
End Function