Experts Exchange connects you with the people and services you need so you can get back to work.
Private Sub cmd_Filter_Click
me.Filter = fnMultiList(me.lst_FilterField)
me.filteron = Len(me.filter) > 0
Open in new window
Public Function fnMultiList(lst As ListBox, Optional SelectAll As Boolean = False, _
Optional UseColumn As Integer = -1) As Variant
Dim varItem As Variant
Dim lngItem As Long
Dim strDelimiter As String
fnMultiList = Null
'Determine how to delimit the list items
If UseColumn = -1 Then UseColumn = lst.BoundColumn - 1
If IsNumeric(lst.Column(UseColumn, Abs(lst.ColumnHeads))) Then
strDelimiter = ""
strDelimiter = Chr$(34)
'loop through the selected items in the list
If lst.MultiSelect = 0 And SelectAll = False Then
fnMultiList = lst.Value
For lngItem = 0 To lst.ListCount
If lst.Selected(lngItem) = True Or SelectAll Then
fnMultiList = (fnMultiList + ",") _
& strDelimiter & lst.Column(UseColumn, lngItem) _
'Strip trailing "," if there is one
If Right(fnMultiList, 1) = "," Then fnMultiList = Left(fnMultiList, Len(fnMultiList) - 1)
'Depending on the number of items selected, determine how the "list values" are returned
If Len(fnMultiList & "") = 0 Then
fnMultiList = " IS NOT NULL"
Select Case Len(fnMultiList) - Len(Replace(fnMultiList, ",", ""))
fnMultiList = " = " & fnMultiList
fnMultiList = " IN (" & fnMultiList & ")"
Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $108.00.
Premium members get this course for $159.20.
Premium members get this course for $259.00.
Premium members get this course for $122.40.
Premium members get this course for $349.00.