IIf statement in access

KatSlif

New Member
Joined
Apr 3, 2014
Messages
28
Hello

I need help with a formula in access please.

I have 12 codes that need to have either the letter A, B or C added to the end of the code depending on the age of a person:

e.g.
codes
AB01
AB02
AB20
AB21

If the persons age is 19 years and over I need an A at the end e.g. AB01A
If the persons age is between 6 and 18 years and over I need a B at the end e.g. AB01B
If the persons age is 5 and under I need a C at the end e.g. AB01C

I have the age calculated its just grouping to the correct code I need help with??

I have had ago:
CODE: IIf(
Code:
 In ("RD01","RD02","RD20","RD21","RN04","RN08","RN16","RN23","RN25","RN29","RN30","RN34"),IIf([Age]<6,[Code&"C"],IIf([Code] In ("RD01","RD02","RD20","RD21","RN04","RN08","RN16","RN23","RN25","RN29","RN30","RN34"),IIf([Age]<19,[Code&"B"],IIf([Code] In ("RD01","RD02","RD20","RD21","RN04","RN08","RN16","RN23","RN25","RN29","RN30","RN34"),IIf([Age]>=19,[Code&"A"]))))))

Any help appreciated
Katherine
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Katherine,
it looks as though it should work, but why have you repeated "IIf(
Code:
 In ("RD01","RD02","RD20","RD21","RN04","RN08","RN16","RN23","RN25","RN29","RN30","RN34")" three times?  If it is true at the start of the statement, it is not going to become false half way through - you only need to test once.  Other than that I can't see why it wouldn't give the result you are looking for assuming that your ages are integers.
Kind regards,
Rob
 
Upvote 0
[MyCode&"B"] is incorrect. You mean [MyCode]&"B"

Code:
CODE: IIf([MyCode] not in 
	("RD01","RD02","RD20","RD21","RN04","RN08","RN16","RN23","RN25","RN29","RN30","RN34"),
	[MyCode],
	IIf([Age]<6,[MyCode]&"C",IIf([Age]<19,[MyCode]&"B",[MyCodeCode]&"A")))

This will not work if Age is null so beware - make sure age is never null or else rewrite the formula to handle that case.
I have provided a values for when MyCode is not in the list of codes - which is to just leave it alone (return [MyCode]).

And I'm calling the field MyCode instead of Code because Code in brackets is a keyword for this website to create a code block.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,700
Messages
6,161,371
Members
451,700
Latest member
Eccymarge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top