Jologs said:
For Each Itm In ctl.ItemsSelected
If Len(Criteria) = 0 Then
Criteria = Chr(34) & ctl.ItemData(Itm) & Chr(34)
Else
Criteria = Criteria & "," & Chr(34) & ctl.ItemData(Itm) &
Chr(34)
End If
Next Itm
Instead of the above, try something like this (aircode adapted from working
code) in the click event of the listbox. The Chr(34) above is a double quote
" used to dilineate a string (text value). Numeric values will not need the
quotes. If the criteria is a string, you'll need to marry the logic above
into this line:
strList = strList & .Column(0, varItem) & ","
As in:
strList = strList & Chr(34) & .Column(0, varItem) & Chr(34) & ","
Dim strList As String
Dim varItem As Variant
With Me!lstWhatever ' Listbox name
If .MultiSelect = 0 Then ' Check if it is a multiselect
Me!txtSelected = .Value ' The textbox holding these
values
Else
For Each varItem In .ItemsSelected
strList = strList & .Column(0, varItem) & ","
Next varItem
If strList <> "" Then
strList = Left$(strList, Len(strList) - 1)
End If
Me.txtSelected = strList
End If
End With
The difference in the code is that my code is adding the comma at the end,
and taking it off if it's not needed.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access