SWITCH
Using the SWITCH Function
In this tutorial you will learn how to use the SWITCH Function.
The SWITCH function returns the associated value from a list.
=SWITCH( ParamArray VarExpr() As Variant )
ParamArray is an Array of values
In this example we will use Grades and their respective points score.
Grade | Score |
A | 90 |
B | 80 |
C | 70 |
D | 60 |
If the [Grade] was 95.
Then the result is "A".
Query
The results using a Query would be
SELECT [Grade], Switch([Grade]>=90, "A", [Grade]>=80, "B", [Grade]>=70, "C", [Grade]<70, "F") FROM CustomerT
FORM
In a Form you could set the Default Value of a Textbox to
=SWITCH([Grade]>=90, "A", [Grade]>=80, "B", [Grade]>=70, "C", [Grade]<70, "F"))
VBA
In a Form add a TEXTBOX control and rename it "txtSWITCH", then you could add the following in the Load Event.
Private Sub Form_Load()
txtSWITCH = SWITCH([Grade]>=90, "A", [Grade]>=80, "B", [Grade]>=70, "C", [Grade]<70, "F"))
End Sub
Courses
Access Expert 25
Search
You can find more about this by searching the website.
By: Alex Hedley
Click here to sign up for more FREE tips
|