If statement to change the value of my data within 1 column? (1 Viewer)

Espinoza84

Registered User.
Local time
Today, 08:32
Joined
May 30, 2008
Messages
55
Hello I have a column named: Grades

Then, I have only 3x different values in the fields under this column

A, B, or C

how do I run a if statement to create a new column trying to accomplish this:

if A then I want it to return 90
if B then I want it to return 80
if C then I want it to return 70

Ideally I want the coding to insert in the
FIELD section of my column ( i am in design view)

Thanks
 
M

Mike375

Guest
You make a new field in your query as follows

NewFieldName: IIf([FieldName] Like "A",90,IIf([FieldName] Like "B",80,IIf([FieldName] Like "C",70)))

Where FieldName is the field in your table where you have the As, Bs and Cs.

Just type it on the field row in query design next to the fields from your table.

Or you can out it in an unbound textbox as the data source. When you do that just enter

=IIf([FieldName] Like "A",90,IIf([FieldName] Like "B",80,IIf([FieldName] Like "C",70)))
 

Espinoza84

Registered User.
Local time
Today, 08:32
Joined
May 30, 2008
Messages
55
Your first code did not work, by the way I am not using 90 80 or 70, but words, dont think thats the issue though.

Any tips?

EDIT: nevermind I put " " around the 90, 80 and 70 and its working now,

thanks for your help peeps
 

Brianwarnock

Retired
Local time
Today, 13:32
Joined
Jun 2, 2003
Messages
12,701
For the future - it helps posters give you the correct answers, including syntax, if you give the correct information 90 is not ninety.

Brian
 
M

Mike375

Guest
Open Query1 in the attached.

Note the IIF statement for both is what I posted except in the second one you will see "Seventy" as opposed to Seventy. You put text between " "

If you leave out the " " around the word then the Query will default to [Ninety] etc which Access then reads as a field as if there was a field called [Ninety] then the IIF statement would insert whatever was in [Ninety]
 

Attachments

  • 70-80-90.zip
    9.4 KB · Views: 92

Users who are viewing this thread

Top Bottom