Thread: classify
View Single Post
  #3  
Old December 7th, 2009, 06:16 PM posted to microsoft.public.access.queries
Dale Fye
external usenet poster
 
Posts: 2,651
Default classify

I prefer Allen's method (relatively easy to implement and extremely easy to
change if you need to make changes to the category ranges). This technique
is also ideal if you are working in a multi-user environment, because changes
to the table in the backend will apply to everyone immediately, without
having to field a new front-end application.

However, there are several other options:

1. Use the Switch function. The Switch function accepts an array of
parameter pairs where the odd numbered parameters are expressions that will
evaluate to True or False. If the expression evaluates to True, then the
even numbered parameter which follows it is what gets returned. If the
expression evaluates to False, then the function goes to the next odd
numbered parameter, and evaluates it.

You can test this in the immediate window by typing

intAge = 5
?switch(intAge 4, 1, intAge = 4.75, 2, intAge 6.3, 3, True, "invalid")

I generally add a parameter pair at the end (as above) which allows me to
identify if none of the conditions specified were met. If you don't do this,
the function will return NULL.

The down side of using this method, is that you have to find each and every
instance where you have used this method if you need to make a simple change
to the values in the expressions that define your categories. If your
application is being used by others, then you have to distribute a new front
end.

2. Another method would be to create a user defined function which you
would pass the age and which would return an age category. This one also has
the drawback that you must distribute a new front-end if you make changes.

Public Function fnAgeCat(dblAge as double) as Integer

if dblAge 3.99 then
fnAgeCat = 1
elseif dblAge = 4.75 then
fnAgeCat = 2
elseif dblAge 6.3 then
fnAgeCat = 3
else
fnAgeCat = 0
endif

End Sub

----
HTH
Dale