• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

In query designer how to use IF,Elseif,else

In access query designer how can I put an if condition. Like if fieldA = this or that then Red.
Else if
fielda = new or old then green
fieldA = yellow.
  • 4
1 Solution
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Switch([FieldA=this or [Fielda] = that,"RED",[FieldA]=New Or [FieldA]= old,That ......)

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
sorry ....

Switch([FieldA=this or [Fielda] = that,"RED",[FieldA]=New Or [FieldA]= old,"GREEN", FieldA<>this AND [Fielda]<> That AND FieldA<>Old and FieldA<>New, "YELLOW"      )
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:

Switch Function

Evaluates a list of expressions and returns a Variant value or an expression associated with the first expression in the list that is True.


Switch(expr-1, value-1[, expr-2, value-2 & [, expr-n,value-n]])

The Switch function syntax has these parts:

Part Description
expr Required. Variant expression you want to evaluate.
value Required. Value or expression to be returned if the corresponding expression is True.


The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren't properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on.

Switch returns a Null value if:

None of the expressions is True.

The first True expression has a corresponding value that is Null.
Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Kenneth MarksProgramming ManagerCommented:

Are you using the query in a report or form? If that is the case, in the report or form design use conditional formating. Hope this helps.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"In access query designer"

Rey Obrero (Capricorn1)Commented:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now