HomePrivacy PolicyFeedbackLink to usSite Map

MS Access: Choose Function


In Access, the Choose function returns a value from a list of values based on a given position.

The syntax for the Choose function is:

Choose ( position, value1, value2, ... value_n )

position is position number in the list of values to return.

value1, value2, ... value_n is a list of values.


Note:

If position is less than 1, the Choose function will return a null value.

If position is greater than the number of values, the Choose function will return a null value.

If position is a fraction (not an integer value), it will be rounded to the nearest whole number.


For example:

Choose(1, "Tech", "on", "the", "Net") would return "Tech"
Choose(2, "Tech", "on", "the", "Net") would return "on"
Choose(3, "Tech", "on", "the", "Net") would return "the"
Choose(4, "Tech", "on", "the", "Net") would return "Net"
Choose(5, "Tech", "on", "the", "Net") would return NULL
Choose(3.75, "Tech", "on", "the", "Net") would return "the"

VBA Code

The Choose function can be used in VBA code. For example:

Dim LValue As String

LValue = Choose(1, "Tech", "on", "the", "Net")

In this example, the variable called LValue would contain "Tech" as a value.


SQL/Queries

You can also use the Choose function in a query.

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