PeterBaileyUk
asked on
Filter string in access
I have a combo that works with a case statement in access vba to take the appropriate filter action:
Forms!cw_client_matching_f orm.Filter = "([ComparitorType] =2)" & StrFilterDate
I had to make a structural strange and [comparitorType] could now contain numerous values ie
1,4
1,7
etc as opposed to one numerical value so how do i change the filter string to reflect that?
like "*2*" ?
if as in my ex
Forms!cw_client_matching_f
I had to make a structural strange and [comparitorType] could now contain numerous values ie
1,4
1,7
etc as opposed to one numerical value so how do i change the filter string to reflect that?
like "*2*" ?
if as in my ex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this: myArray() = Split(TestAgainst, ",") gives type mismatch
?fnStringContains("1","1,2 ")
?fnStringContains("1","1,2
Public Function fnStringContains(TestValue As String, TestAgainst As Variant) As Boolean
'TestAgainst is a variant so that if you pass a NULL value from your field, it can be handled properly
Dim myArray() As Variant
Dim intLoop As Integer
'Default return value is False
fnStringContains = False
If IsNull(TestAgainst) Then Exit Function
'parse TestAgainst on commas
myArray() = Split(TestAgainst, ",")
'Check each element of myArray
For intLoop = LBound(myArray) To UBound(myArray)
If myArray(intLoop) = TestValue Then Exit For
Next
End Function
Try this, it didn't like myArray() being defined as variant.
Public Function fnStringContains(TestValue As String, TestAgainst As Variant) As Boolean
'TestAgainst is a variant so that if you pass a NULL value from your field, it can be handled properly
Dim myArray() As String
Dim intLoop As Integer
'Default return value is False
fnStringContains = False
If IsNull(TestAgainst) Then Exit Function
'parse TestAgainst on commas
myArray() = Split(TestAgainst, ",")
'Check each element of myArray
For intLoop = LBound(myArray) To UBound(myArray)
If myArray(intLoop) = TestValue Then
fnStringContains = True
Exit For
End If
Next
End Function
It is really NEVER a good idea to store MORE THAN ONE PIECE of information in a field!