I am using a simple form to set filter options to a query. One of my fields is a [FONT="]Multi Selection list box [/FONT][FONT="]which users can select 1 or more options. The [/FONT][FONT="]selected items in the multiple selection list box is stored in a comma-delimited string programmatically called “Selections” which, is included as part of the query filter as “In ([Forms]![View Reports]![Selections])”. The following code works great if users only pick 1 selection on the list box. Nothing works when multiple values are selected. :banghead:[/FONT]
Any help would be greatly appreciated.
Thank you,
Any help would be greatly appreciated.
Thank you,
Code:
Option Compare Database
Option Explicit
Private Sub Form_Current()
Dim oItem As Variant
Dim bFound As Boolean
Dim sTemp As String
Dim sValue As String
Dim sChar As String
Dim iCount As Integer
Dim iListItemsCount As Integer
sTemp = Nz(Me!Selections.Value, " ")
iListItemsCount = 0
bFound = False
iCount = 0
Call clearListBox
For iCount = 1 To Len(sTemp) + 1
sChar = Mid(sTemp, iCount, 1)
If StrComp(sChar, " , ") = 0 Or iCount = Len(sTemp) + 1 Then
bFound = False
Do
If StrComp(Trim(Me!AccruList.ItemData(iListItemsCount)), Trim(sValue)) = 0 Then
Me!AccruList.Selected(iListItemsCount) = True
bFound = True
End If
iListItemsCount = iListItemsCount + 1
Loop Until bFound = True Or iListItemsCount = Me!AccruList.ListCount
sValue = ""
Else
sValue = sValue & sChar
End If
Next iCount
End Sub
Private Sub clearListBox()
Dim iCount As Integer
For iCount = 0 To Me!AccruList.ListCount
Me!AccruList.Selected(iCount) = False
Next iCount
End Sub
Private Sub multiselect_Click()
Dim oItem As Variant
Dim sTemp As String
Dim iCount As Integer
iCount = 0
If Me!AccruList.ItemsSelected.Count <> 0 Then
For Each oItem In Me!AccruList.ItemsSelected
If iCount = 0 Then
sTemp = sTemp & Me!AccruList.ItemData(oItem)
iCount = iCount + 1
Else
sTemp = sTemp & " , " & Me!AccruList.ItemData(oItem)
iCount = iCount + 1
End If
Next oItem
Else
MsgBox "Nothing was selected from the list", vbInformation
Exit Sub 'Nothing was selected
End If
Me!Selections.Value = sTemp
End Sub
Private Sub clrList_Click()
Call clearListBox
Me!mySelections.Value = Null
End Sub
Last edited by a moderator: