tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment

Other Sites

CheckYourMath BigActivities DigMinecraft
Share this page:

MS Access: Switch Function

Learn how to use the Access Switch function with syntax and examples.

Description

The Microsoft Access Switch function evaluates a list of expressions and returns the corresponding value for the first expression in the list that is TRUE.

Syntax

The syntax for the Microsoft Access Switch function is:

Switch ( expression1, value1, expression2, value2, ... expression_n, value_n )

Parameters or Arguments

expression1, expression2, expression_n is a list of expressions that are evaluated. The Switch function is looking for the first expression that evaluates to TRUE.

value1, value2, ... value_n is a list of values. The Switch function will return the value associated with the first expression that evaluates to TRUE.

Applies To

The Switch function can be used in the following versions of Microsoft Access:

Example

Switch (SupplierID=1, "IBM", SupplierID=2, "HP", SupplierID=3, "Nvidia")

In this example, if the SupplierID field is 1, then the Switch function will return "IBM".
If the SupplierID field is 2, then the Switch function will return "HP".
If the SupplierID field is 3, then the Switch function will return "Nvidia".

Example (in VBA Code)

The Switch function can be used in VBA code in Microsoft Access. For example:

Dim LValue As String

LValue = Switch (SupplierID=1, "IBM", SupplierID=2, "HP", SupplierID=3, "Nvidia")

Example (in SQL/Queries)

You can also use the Switch function in a query in Microsoft Access.

Microsoft Access

In this example, if the SupplierID field is 1, then the Switch function will return "IBM".
If the SupplierID field is 2, then the Switch function will return "HP".
If the SupplierID field is 3, then the Switch function will return "Nvidia".