Hello... I've read through several related topics here, but can't find a way to make this work.
I have a multi-select (Branch List) list box on my form (Main Menu) in which I need to create a string based on the selected branches and use as the criteria for my query.
I have the following code to build the string in a module:
Public Function basBuildWhereString() As String
Dim varItem As Variant
Dim intI As Integer
If Forms("Main Menu")![Branch List].ItemsSelected.Count > 0 Then
intI = 1
For Each varItem In Forms("Main Menu")![Branch List].ItemsSelected
basBuildWhereString = basBuildWhereString & """" & Forms("Main Menu")![Branch List].ItemData(varItem) & """"
If Forms("Main Menu")![Branch List].ItemsSelected.Count > intI Then
basBuildWhereString = basBuildWhereString & " Or "
intI = intI + 1
End If
Next varItem
End If
MsgBox (basBuildWhereString)
End Function
I have this function name in the criteria field of my query. The string is built correctly, as verified by the MsgBox function, however the query is not filtered per this string.
Any suggestions?
I have a multi-select (Branch List) list box on my form (Main Menu) in which I need to create a string based on the selected branches and use as the criteria for my query.
I have the following code to build the string in a module:
Public Function basBuildWhereString() As String
Dim varItem As Variant
Dim intI As Integer
If Forms("Main Menu")![Branch List].ItemsSelected.Count > 0 Then
intI = 1
For Each varItem In Forms("Main Menu")![Branch List].ItemsSelected
basBuildWhereString = basBuildWhereString & """" & Forms("Main Menu")![Branch List].ItemData(varItem) & """"
If Forms("Main Menu")![Branch List].ItemsSelected.Count > intI Then
basBuildWhereString = basBuildWhereString & " Or "
intI = intI + 1
End If
Next varItem
End If
MsgBox (basBuildWhereString)
End Function
I have this function name in the criteria field of my query. The string is built correctly, as verified by the MsgBox function, however the query is not filtered per this string.
Any suggestions?