# Thread: Multiple choices for IF THen statement

1. Registered User
Join Date
Sep 2007
Posts
14

## Unanswered: Multiple choices for IF THen statement

I need to create an IF statement that will read a value and return one of four choices: values of 13-14=E, 12=G, 10-11=F, 0-9=N.

I can handle the if then else but the I can figure out the 4th choice.

2. Registered User
Join Date
Apr 2004
Location
metro Detroit
Posts
634
You need a nested if statement, select case statement, or the switch function depending on where you're doing this. Check the Access help file for details on all of them.

3. Registered User
Join Date
Jun 2007
Location
Maitland NSW,Australia
Posts
401
With a mutli level IF statements it can become very complex and difficult to debug. I suggest you use a Select Case Statement.

my_value is the value that you are reading, new_value is your return value
I assume the numbers are integers, if they are string they need to enclosed in ""
Select Case my_value
Case 0,1,2,3,4,5,6,7,8,9
new_value= "N"

Case 10,11
new_value = "F"

Case 12
new_value ="G"

Case 13,14
new_value="E"
End Select

4. Registered User
Join Date
Sep 2007
Posts
14
I'm trying to generate this result in a report using the expression builder.

How would I write that?
Then entry will be one value between 0 to 14 with 13 to 14 = E, 12=G, 10 to 11=F, 0 to 9 = N

5. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
Iif(foo in (13,14),'E',Iif(foo=12,'G',Iif(foo in (10,11),'F','N')))

6. Registered User
Join Date
Oct 2002
Location
Posts
697
You are such a bunch of n00bs.

Code:
`mid\$("NNNNNNNNNNFFGEE", score + 1, 1)`

7. King of Understatement
Join Date
Feb 2004
Location
One Flump in One Place
Posts
14,912
Depending on the specific circumstances of course, I would skip the code altogether and put this into a table. If you have these numbers in a table already then this letter thingy should really be considered an attribute of the entity. Apart from owt else - it means you do not need to rewrite the code everywhere you need it or if you migrate your FE to another platform.

8. www.gvee.co.uk
Join Date
Jan 2007
Location
UK
Posts
11,445
Can we use:
Code:
`CASE WHEN value LIKE '[0-9]' THEN 'N' ...`
?

9. Registered User
Join Date
Jul 2006
Posts
108
or, do what i did and be stubborn. ignore the smart peoples advise and use the multi-if statements

if ...then
code me
elseif ... then
code me
elseif ... then
code me
else ... then
code me
endif

then a yr down the road you try to do it and screw up and spend 3 weeks, day and night to find the error in a 160 line if...then statement.

ahhh the good old days.

10. Registered User
Join Date
Sep 2006
Posts
265
I would be tempted to use a table to resolve your problem. If you create a Table with 0-14 records and their classification there is no need of a if or case. If 15 is then used you simply add it to your Table.

Simon

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•