I have a list box populated from a table. I want the user to select one or more values in the listbox and build an SQL statement with the selected items. The Multi Select is set to "Simple"
So far, this is what I have in my code. I pass in the name of the list control and the fieldname. But when the 1st line after the "For" statement is exeucted, I get the error message "Object doesn't support this property or Method" Does anyone have any idea why? Or any idea how to capture the selected items in the list box?
Function fncAddSQL(ctlList As Control, strFieldName As String)
Dim varItem As Variant
Dim strNewSQL As String
Dim strValue As String
For Each varItem In ctlList.ItemsSelected
strValue = ctlList.ItemdData(varItem)
strNewSQL = "AND [" & strFieldName & "] = '" & strValue & "' "
Next varItem
End Function
After this is run, I will add the strNewSQL to my Where clause, but I can't get this part to work.
So far, this is what I have in my code. I pass in the name of the list control and the fieldname. But when the 1st line after the "For" statement is exeucted, I get the error message "Object doesn't support this property or Method" Does anyone have any idea why? Or any idea how to capture the selected items in the list box?
Function fncAddSQL(ctlList As Control, strFieldName As String)
Dim varItem As Variant
Dim strNewSQL As String
Dim strValue As String
For Each varItem In ctlList.ItemsSelected
strValue = ctlList.ItemdData(varItem)
strNewSQL = "AND [" & strFieldName & "] = '" & strValue & "' "
Next varItem
End Function
After this is run, I will add the strNewSQL to my Where clause, but I can't get this part to work.