Public Function getLBX(lbx As ListBox, Optional intColumn As Variant = 0, Optional Seperator As String = ",", _
Optional Delim As Variant = Null) As String
'Iterates thru the multiselect listbox and constructs an array of the selected items
'Arguments:
'Lbx is Listbox Object ie.Me.MyListbox
'intColumn is the column # to be returned
'Seperator is the character seperating items in array returned
'Delim is optional delimiter to be return in array ie. #1/1/2001#,#12/25/2015#
Dim strList As String
Dim varSelected As Variant
'On Error GoTo getLBX_Error
If lbx.ItemsSelected.Count = 0 Then
'MsgBox "Nothing selected"
Else
For Each varSelected In lbx.ItemsSelected
If Nz(lbx.Column(intColumn, (varSelected)), "") <> "" Then
strList = strList & Delim & lbx.Column(intColumn, (varSelected)) & Delim & Seperator
Else
strList = strList
End If
Next varSelected
If Nz(strList, "") <> "" Then
strList = Left$(strList, Len(strList) - 1) 'remove trailing comma
End If
End If
getLBX = strList
On Error GoTo 0
Exit Function
getLBX_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure getLBX of Module modLBX"
End Function