I have made this code which collects the value of the bound column of a multiselect list box and creates a string that I want to use in the criteria field for a query:
Public Function PrintExemptionVendorRows()
Dim ctlList As Control, varItem As Variant, strCollect As String
' Return Control object variable pointing to list box.
Set ctlList = Forms![frmPrintExemptionSummary]![List8]
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 = ctlList.ItemData(varItem)
Else: strCollect = strCollect & " or " & ctlList.ItemData(varItem)
End If
' Debug.Print strCollect
Next varItem
PrintExemptionVendorRows = strCollect
' Debug.Print PrintExemptionVendorRows
End Function
What I end up with is a string looking like this: 11 or 14 or 16 or 88 or 92
I put the statement PrintExemptionVendorRows() in the criteria field of the query I want to run with the above statement as criteria. However, when I run the query I get no results, as if the query doesn't see the function as a query statement, but perhaps as a text string; as if "11 or 14 or 16 or 88 or 92" is within quotes, which WOULD give me no results.
Can anyone help me figure out what I'm doing wrong? Thanks
Robin
Public Function PrintExemptionVendorRows()
Dim ctlList As Control, varItem As Variant, strCollect As String
' Return Control object variable pointing to list box.
Set ctlList = Forms![frmPrintExemptionSummary]![List8]
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 = ctlList.ItemData(varItem)
Else: strCollect = strCollect & " or " & ctlList.ItemData(varItem)
End If
' Debug.Print strCollect
Next varItem
PrintExemptionVendorRows = strCollect
' Debug.Print PrintExemptionVendorRows
End Function
What I end up with is a string looking like this: 11 or 14 or 16 or 88 or 92
I put the statement PrintExemptionVendorRows() in the criteria field of the query I want to run with the above statement as criteria. However, when I run the query I get no results, as if the query doesn't see the function as a query statement, but perhaps as a text string; as if "11 or 14 or 16 or 88 or 92" is within quotes, which WOULD give me no results.
Can anyone help me figure out what I'm doing wrong? Thanks
Robin