Tuesday, June 21, 2005

Choose Function

It's been a while since I've come across a new VBA function that I haven't used before AND find useful. The Choose function has similar functionality to the VLookup function in Excel. If you need to lookup a value but can't justify storing the values in an array, table, or lookup list, then the Choose function might be a good alternative.
Syntax

Choose(index, choice-1[, choice-2, ... [, choice-n]])

I recently used this in a database I was working with a database which tracks driver information for a trucking company. The driver classification was one of the fields in the database (not designed by me). I wanted to hide the classifications in code, so that some relatively savey Access user couldn't alter the 'lookup' field. So, I started to build my own lookup when I found the Choose function. I used it as the control source of one the driver classification text box on a form:

=Choose([class],"Experienced","Veteran","Suspended")

If the [class] had a value of 1, then the text box displayed "Experienced", 2 displayed "Veteran", and 3 displayed "Suspended."

I used the Choose function so that I could hide the three values in code and because I didn't want to add another table to the database to store just three values (which SHOULD never change). One other side note was that I knew that the [class] field was only being displayed on one form, otherwise I would have made my own Public function to display the results of the Choose function.

1 comment:

香港咨询 said...

Step 2. Scan and Android Data Recovery the deleted files on your phone
Select the specific file you need, start the program to search your lost data.