using OR in a global variable as criteria query on a report

Jaymin

Registered User.
Local time
Today, 11:47
Joined
Oct 24, 2011
Messages
70
Hi Guys, :banghead::banghead:
if i type into the criteria = "face" or "hands" or "feet"
the returns are OK. and if i create a global variable and use only one of the criterias eg Bodyparts = "feet" and enter it in the criteria as Bodyparts() all works OK.
but if i give the Bodyparts = ""face" or "hands" or "feet"" the variable accepts it but the criteria does not work, can anyone give me an idea how to use the "OR" criteria with a global variable
many thanks
 
Using the Design viewer, you can't. To acheive what you want, you should create a custom function the does the comparison and returns True or False if it matches Bodyparts and then use that function as a new field in a query, underwhich you put the criteria True.

The function would look like this (not tested code, so don't yell when it doesn't work):

Code:
Dim BodyParts = "Eye,Uvula,Knee,Coccyx"  
    ' The global BodyParts variable should like like the above--all body parts seperated by commas 

Function matches_BodyParts(in_BodyPart) AS Boolean
    ' compares in_BodyPart to see if it is in BodyParts

ret = False    ' return value, default to no match

if(InStr(BodyParts, in_BodyParts)>0) Then ret = True

matches_BodyParts = ret

End Function

Then, in the query it would look like this:

MatchesBodyParts: matches_BodyParts([BodyPartField])

Underneath you put your True criteria.
 
Thanks Plog for your quick responce, give me a couple of days i will get back if i can get it to work, plus have alot of trouble with internet, provider has gone on holidays no access.
 
hi plog,
when i use your code i get an error
Dim BodyParts = "Eye,Uvula,Knee,Coccyx"
' The global BodyParts variable should like like the above--all body parts seperated by commas
 
How did you declare your global variable prior to my code? Do it that way.
 

Users who are viewing this thread

Back
Top Bottom