If Then Statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i am trying to create an if then statement on a form using the statement in
the control field below... I have a total of 7 workcenters i need to use.
What am i doing wrong? ( I can not program effectivly so browsed the forums
and found this formula and am trying to adapt it to my use.)

=IIf(([WORK CENTER]="ATC","ATC"),IIf([WORK CENTER]="OE20","Comms"),IIf([WORK
CENTER]="OE30","Comms"))

The only one that works is OE30

ATC should = ATC
OE20 = Comms
OE30 = Comms
OE40 = Radar
and so on
 
To use IIf statements like that, you need to nest them appropriately:

=IIf([WORK CENTER]="ATC","ATC",IIf([WORK CENTER]="OE20","Comms",IIf([WORK
CENTER]="OE30","Comms", "Unknown")))

You might find it easier to use the Switch function, though:

=Switch([WORK CENTER]="ATC", "ATC", [WORK CENTER]="OE20", "Comms", [WORK
CENTER]="OE30", "Comms", "Unknown")
 
I would use either a lookup table that describes the values or a small
user-defined function that can be used everywhere. I ALWAYS assume this data
will change. Work Centers will be added, deleted, or modified. I would not
want to maintain expressions in control sources or queries. I would rather
maintain data (or let someone else do it :-)

--
Duane Hookom
MS Access MVP

Douglas J. Steele said:
To use IIf statements like that, you need to nest them appropriately:

=IIf([WORK CENTER]="ATC","ATC",IIf([WORK CENTER]="OE20","Comms",IIf([WORK
CENTER]="OE30","Comms", "Unknown")))

You might find it easier to use the Switch function, though:

=Switch([WORK CENTER]="ATC", "ATC", [WORK CENTER]="OE20", "Comms", [WORK
CENTER]="OE30", "Comms", "Unknown")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


CiceroCF said:
i am trying to create an if then statement on a form using the statement
in
the control field below... I have a total of 7 workcenters i need to
use.
What am i doing wrong? ( I can not program effectivly so browsed the
forums
and found this formula and am trying to adapt it to my use.)

=IIf(([WORK CENTER]="ATC","ATC"),IIf([WORK
CENTER]="OE20","Comms"),IIf([WORK
CENTER]="OE30","Comms"))

The only one that works is OE30

ATC should = ATC
OE20 = Comms
OE30 = Comms
OE40 = Radar
and so on
 
Good point, Duane. That's what happens when you only look at the question,
and not the context!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Duane Hookom said:
I would use either a lookup table that describes the values or a small
user-defined function that can be used everywhere. I ALWAYS assume this
data will change. Work Centers will be added, deleted, or modified. I would
not want to maintain expressions in control sources or queries. I would
rather maintain data (or let someone else do it :-)

--
Duane Hookom
MS Access MVP

Douglas J. Steele said:
To use IIf statements like that, you need to nest them appropriately:

=IIf([WORK CENTER]="ATC","ATC",IIf([WORK CENTER]="OE20","Comms",IIf([WORK
CENTER]="OE30","Comms", "Unknown")))

You might find it easier to use the Switch function, though:

=Switch([WORK CENTER]="ATC", "ATC", [WORK CENTER]="OE20", "Comms", [WORK
CENTER]="OE30", "Comms", "Unknown")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


CiceroCF said:
i am trying to create an if then statement on a form using the statement
in
the control field below... I have a total of 7 workcenters i need to
use.
What am i doing wrong? ( I can not program effectivly so browsed the
forums
and found this formula and am trying to adapt it to my use.)

=IIf(([WORK CENTER]="ATC","ATC"),IIf([WORK
CENTER]="OE20","Comms"),IIf([WORK
CENTER]="OE30","Comms"))

The only one that works is OE30

ATC should = ATC
OE20 = Comms
OE30 = Comms
OE40 = Radar
and so on
 
I've never done that before ;-)


--
Duane Hookom
MS Access MVP

Douglas J. Steele said:
Good point, Duane. That's what happens when you only look at the question,
and not the context!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Duane Hookom said:
I would use either a lookup table that describes the values or a small
user-defined function that can be used everywhere. I ALWAYS assume this
data will change. Work Centers will be added, deleted, or modified. I
would not want to maintain expressions in control sources or queries. I
would rather maintain data (or let someone else do it :-)

--
Duane Hookom
MS Access MVP

Douglas J. Steele said:
To use IIf statements like that, you need to nest them appropriately:

=IIf([WORK CENTER]="ATC","ATC",IIf([WORK
CENTER]="OE20","Comms",IIf([WORK CENTER]="OE30","Comms", "Unknown")))

You might find it easier to use the Switch function, though:

=Switch([WORK CENTER]="ATC", "ATC", [WORK CENTER]="OE20", "Comms", [WORK
CENTER]="OE30", "Comms", "Unknown")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


i am trying to create an if then statement on a form using the statement
in
the control field below... I have a total of 7 workcenters i need to
use.
What am i doing wrong? ( I can not program effectivly so browsed the
forums
and found this formula and am trying to adapt it to my use.)

=IIf(([WORK CENTER]="ATC","ATC"),IIf([WORK
CENTER]="OE20","Comms"),IIf([WORK
CENTER]="OE30","Comms"))

The only one that works is OE30

ATC should = ATC
OE20 = Comms
OE30 = Comms
OE40 = Radar
and so on
 
Back
Top