complex if statement

R

Richard

What is best way to create a variable that depends on five different fields
and is defined by multiple rules. This is similar to CASE or ELSE IF
statements in Excel.

Something like:
If a>2, b="Car", c=10, d="Fix" then x = "Fancy"
else if a<2, b="van", d="Brake" then x = "Plain"
else if a>5, b="truck" then x = "Big"
else x = "Unknown"
End if

I've looked at IIF function, but have too many dependencies and rules to
keep format of statement tenable.
 
J

John Spencer

You could try the SWITCH Function. Or you could write a custom VBA function
and pass the arguments in. Of you could use a nested IIF statement.


SWITCH(A>2 and B="Car" and C=10 and D="Fix", "Fancy", a<2 and b="van" and
d="Brake" ,"Plain", a>5 and b="truck","Big", True, "Unknown")


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top