Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Filter string in access

Posted on 2011-05-09
4
Medium Priority
?
223 Views
Last Modified: 2012-05-11
I have a combo that works with a case statement in access vba to take the appropriate filter action:

 Forms!cw_client_matching_form.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
0
Comment
Question by:PeterBaileyUk
  • 3
4 Comments
 
LVL 49

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 35720855
It is really NEVER a good idea to store one piece of information in a field!

Well, the problem with "*2*" is that it would evaluate to True for 2, 12, 20, 21, ..29, 32,...  and testing for *,2* or *2," will return basically the same set, although it would potentially rule out either the first of last entry in the list

Is the field type of [ComparitorType] now a string?  If so, you could write a function and call that, something like:

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

You would then call this function something like:

Forms!cw_Client_Matching_Form.Filter = "fnStringContains('2', [ComparitorType]) & strFilterDate

0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 35721083
That should have read:

It is really NEVER a good idea to store MORE THAN ONE PIECE of information in a field!
0
 

Author Comment

by:PeterBaileyUk
ID: 35726119
this:  myArray() = Split(TestAgainst, ",")  gives type mismatch

?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

Open in new window

0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 35729733
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

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question