Public Enum eDelimiterType
NoDelimiter = 0
DoubleQuotes = 1
Octothorpes = 2
SingleQuotes = 3
End Enum
Public Enum eSeperatorType
Comma = 0
Pipe = 1
SemiColon = 2
Tilde = 3
NewLine = 4
End Enum
' ----------------------------------------------------------------
' Procedure Name: fGetLbx
' Purpose: Get array of item in a multiselect listbox
' Procedure Kind: Function
' Procedure Access: Public
' Parameter lbx (ListBox): Your listbox object (ie. Me.MyList)
' Parameter intColumn (Integer): The listbox column to return
' Parameter Seperator (eSeperatorType): character seperating the array values
' Parameter Delimiter (eDelimiterType): Delimiters for array values (ie.Double Quotes or Octothorpes)
' Return Type: Variant
' Author: Moke123
'
' **** NOTE **** Returns Null if no items selected. Use NZ() in calling code to handle nulls
'
' ----------------------------------------------------------------
Public Function fGetLbx(Lbx As ListBox, Optional intColumn As Integer = 0, Optional Seperator As eSeperatorType = 0, _
Optional Delimiter As eDelimiterType = 0) As Variant
On Error GoTo fGetLbx_Error
Dim strlist As String, varSelected As Variant, DeLimit As Variant, SepChar As String
Select Case Delimiter
Case 0
DeLimit = Null
Case 1
DeLimit = Chr(34) 'Quotes
Case 2
DeLimit = Chr(35) 'Octothorpes
Case 3
DeLimit = Chr(39) 'SingleQuotes
End Select
Select Case Seperator
Case 0
SepChar = Chr(44) 'comma
Case 1
SepChar = Chr(124) 'pipe
Case 2
SepChar = Chr(59) 'semicolon
Case 3
SepChar = Chr(126) 'tilde
Case 4
SepChar = vbNewLine 'newline
End Select
If Lbx.ItemsSelected.Count > 0 Then
For Each varSelected In Lbx.ItemsSelected
If Lbx.Column(intColumn, (varSelected)) <> "" Then
If strlist <> "" Then
strlist = strlist & SepChar & DeLimit & Lbx.Column(intColumn, (varSelected)) & DeLimit
Else
strlist = DeLimit & Lbx.Column(intColumn, (varSelected)) & DeLimit
End If
End If
Next varSelected
fGetLbx = strlist
Else
fGetLbx = Null
End If
On Error GoTo 0
Exit Function
fGetLbx_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure fGetLbx, line " & Erl & "."
End Function
Public Function Dlmt(objIN As Variant, Optional Delimiter As eDelimiterType = 1) As Variant
'returns the passed in value wrapped with the selected delimiter
On Error GoTo Dlmt_Error
Dim DeLimit As String
Select Case Delimiter
Case 0
DeLimit = Null
Case 1
DeLimit = Chr(34) 'Quotes
Case 2
DeLimit = Chr(35) 'Octothorpes
Case 3
DeLimit = Chr(39) 'SingleQuotes
End Select
Dlmt = DeLimit & objIN & DeLimit
On Error GoTo 0
Exit Function
Dlmt_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Dlmt, line " & Erl & "."
End Function