I copied the following code from another post (Bob Scriver created the code). It is working (well sort of working) in a list box with multiselect set to simple. The problem is that it only works for values that are 10 and above. When I select any of the values 1 through 9 I get nothing in the report. Or if I select 3 and 12 I only get 12.
Any help is appreciated.
Public Function ViewCriteriaResults()
Dim ctlList As Control, varItem As Variant, strCollect As String
'Return control object variable pointing to the list box.
Set ctlList = Forms![criteria]![lstCriteria]
strCollect = Empty
'enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
'Create a list of the values of the bound columns of the listbox selection.
If strCollect = Empty Then
strCollect = " or " & CStr(ctlList.ItemData(varItem))
Else: strCollect = strCollect & " or " & CStr(ctlList.ItemData(varItem))
End If
'Debug.Print strCollect
Next varItem
ViewCriteriaResults = strCollect & " or "
'debug.print ViewCriteriaResults
End Function
TIA,
Melanie
Any help is appreciated.
Public Function ViewCriteriaResults()
Dim ctlList As Control, varItem As Variant, strCollect As String
'Return control object variable pointing to the list box.
Set ctlList = Forms![criteria]![lstCriteria]
strCollect = Empty
'enumerate through selected items.
For Each varItem In ctlList.ItemsSelected
'Create a list of the values of the bound columns of the listbox selection.
If strCollect = Empty Then
strCollect = " or " & CStr(ctlList.ItemData(varItem))
Else: strCollect = strCollect & " or " & CStr(ctlList.ItemData(varItem))
End If
'Debug.Print strCollect
Next varItem
ViewCriteriaResults = strCollect & " or "
'debug.print ViewCriteriaResults
End Function
TIA,
Melanie