G
Guest
I am trying to populate a field based on an IIF statement in a query. My
problem is I need to be able to create an expression string.
I need basically for the field to populate itself with different criteria
based on a string of IIF statements.
Basics are that if the Age field is less than or equal to 3, then populate
Grade field as ES and if the Age field is equal to 4 populate Grade field
with PK and if Age field is equal to or greater than 5 popoulate Grade field
with K, etc.
(Age field data is dervied from an update query where the expression is
written to return the age of a person based on today's date and their
birthdate.)
I wrote the following expression in a query:
=IIf([Age]<=3, "ES") and it works just fine, but if I try to add additional
expressions so that I can get one thing if a condition is true, or another if
another condition is true, I am getting a syntax error.
I tried this but this is where I get the syntax error:
=IIf([Age]<=3, "ES"), IIf([Age]=4, "PK"), IIf([Age]>=5, "K")
I know I have written a string of IIf statements before, but i can't
remember how.
I also tried writing separate expressions in the query, which do return the
correct data, but then, of course, it is all in different fields. Is there a
way to maybe do a make table query based on the separate expressions, then
write some sort of query that would put them all in one field?
Thanks so much for any help anyone can give!
problem is I need to be able to create an expression string.
I need basically for the field to populate itself with different criteria
based on a string of IIF statements.
Basics are that if the Age field is less than or equal to 3, then populate
Grade field as ES and if the Age field is equal to 4 populate Grade field
with PK and if Age field is equal to or greater than 5 popoulate Grade field
with K, etc.
(Age field data is dervied from an update query where the expression is
written to return the age of a person based on today's date and their
birthdate.)
I wrote the following expression in a query:
=IIf([Age]<=3, "ES") and it works just fine, but if I try to add additional
expressions so that I can get one thing if a condition is true, or another if
another condition is true, I am getting a syntax error.
I tried this but this is where I get the syntax error:
=IIf([Age]<=3, "ES"), IIf([Age]=4, "PK"), IIf([Age]>=5, "K")
I know I have written a string of IIf statements before, but i can't
remember how.
I also tried writing separate expressions in the query, which do return the
correct data, but then, of course, it is all in different fields. Is there a
way to maybe do a make table query based on the separate expressions, then
write some sort of query that would put them all in one field?
Thanks so much for any help anyone can give!