I use the code below to create the variables for the IN() function. My goal is to create a string with the following format "abc","def". This string will be used as a variable in the IN() function.
For each item selected the code below creates a string with beginning and ending quotes and a comma after the ending quote.
lst_applications is a multi-select list box. When the user makes a selection from the listbox, the selected items appear in a a textbox called txtAppSelected.
My problem is that once all the list items are converted to a string in "abc", "def", format an extra comma exists at the end of the string. This extra comma will create an error when the string is used in the IN() function.
How do you test for the last item selected in a multi-select list box?
Private Sub lst_applications_AfterUpdate()
' Print the list of selected items to the text
' box txtSelected.
Dim varItem As Variant
Dim strList As String
Dim strTemp As String
Dim strQuote As String
strQuote = Chr$(34)
With Me!lst_applications
If .MultiSelect = 0 Then
Me!txtAppSelected = .Value
Else
For Each varItem In .ItemsSelected
strTemp = strQuote & .Column(0, varItem) & strQuote & ","
strList = strList & strTemp
End If
Next varItem
Me!txtAppSelected = strList
End With
End Sub
Thank you in advance for your help.
For each item selected the code below creates a string with beginning and ending quotes and a comma after the ending quote.
lst_applications is a multi-select list box. When the user makes a selection from the listbox, the selected items appear in a a textbox called txtAppSelected.
My problem is that once all the list items are converted to a string in "abc", "def", format an extra comma exists at the end of the string. This extra comma will create an error when the string is used in the IN() function.
How do you test for the last item selected in a multi-select list box?
Private Sub lst_applications_AfterUpdate()
' Print the list of selected items to the text
' box txtSelected.
Dim varItem As Variant
Dim strList As String
Dim strTemp As String
Dim strQuote As String
strQuote = Chr$(34)
With Me!lst_applications
If .MultiSelect = 0 Then
Me!txtAppSelected = .Value
Else
For Each varItem In .ItemsSelected
strTemp = strQuote & .Column(0, varItem) & strQuote & ","
strList = strList & strTemp
End If
Next varItem
Me!txtAppSelected = strList
End With
End Sub
Thank you in advance for your help.