The SelItemData and SelText properties contains strange ASCII control character (28, FileSeparator)
(see https://theasciicode.com.ar/ table)
To reproduce issue in the original project add this code to form:
After run the project add in combo countries:
Sri Lanka,Zambia,Jamaica
Click on txtSelectedItemData and in Immediate windows you see:Code:Private Sub txtSelectedItemData_Click() Dim i As Long Dim SelItems As String SelItems = CheckBoxCombo1.SelItemData For i = 1 To Len(SelItems) Debug.Print i, Chr$(Asc(Mid$(SelItems, i, 1))), Asc(Mid$(SelItems, i, 1)) Next i End Sub
Code:1 1 49 2 , 44 3 28 4 4 52 5 , 44 6 28 7 6 54
Click on txtSelectedText and in Immediate windows you see:Code:Private Sub txtSelectedText_Click() Dim i As Long Dim SelText As String SelText = CheckBoxCombo1.SelItem For i = 1 To Len(SelText) Debug.Print i, Chr$(Asc(Mid$(SelText, i, 1))), Asc(Mid$(SelText, i, 1)) Next i End Sub
Code:1 S 83 2 r 114 3 i 105 4 32 5 L 76 6 a 97 7 n 110 8 k 107 9 a 97 10 , 44 11 28 12 Z 90 13 a 97 14 m 109 15 b 98 16 i 105 17 a 97 18 , 44 19 28 20 J 74 21 a 97 22 m 109 23 a 97 24 i 105 25 c 99 26 a 97
So, if we try to use the SelItemData value with IN operator in a query, i.e. :
We get a sintax error.Code:SELECT * FROM MyTable WHERE ID IN (" & CheckBoxCombo1 & ")"
EDIT: seem the same problem for txtSelectedIndexes...
EDIT2: to solve this issue we have to re-elaborate the property. Example:
Code:Dim SelItems As String Dim newSelItmes As String SelItems = cbo.SelItemData newSelItems = vbNullString If SelItems > vbNullString Then For i = 1 To Len(SelItems) If Mid$(SelItems, i, 1) <> vbNullString Then If Asc(Mid$(SelItems, i, 1)) <> 28 Then 'Debug.Print i, Chr$(Asc(Mid$(SelItems, i, 1))), Asc(Mid$(SelItems, i, 1)) newSelItems = newSelItems & Chr$(Asc(Mid$(SelItems, i, 1))) End If End If Next i Debug.Print newSelItems End If




Reply With Quote