Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: IIF statement


Message #1 by "Joseph Valdez" <e-valdez@a...> on Fri, 14 Mar 2003 09:38:01 -0800
How would you write an IIF statement if you have three choices instead of
two.

For example: field values are: 0,1,2

I thought IIF is only for two choices or am I misunderstood its usage. as

IIF([field1]=0, "Good","BAD")
 Here I knew that if field1 = 0 it is good otherwise it is 1 which is bad.

Question is how about 2? which is in between

I'm confuse.

Maybe someone would know.

Thanks

Message #2 by Lonnie Johnson <prodevmg@y...> on Fri, 14 Mar 2003 07:48:36 -0800 (PST)
Nest another IIF inside the fisrt IIF.
IIf([MyField] = 0, "Good", IIF([MyField] = 1, "Bad", "Undecided"))
 
 Joseph Valdez <e-valdez@a...> wrote:How would you write an IIF statement if you have three choices instead of
two.

For example: field values are: 0,1,2

I thought IIF is only for two choices or am I misunderstood its usage. as

IIF([field1]=0, "Good","BAD")
Here I knew that if field1 = 0 it is good otherwise it is 1 which is bad.

Question is how about 2? which is in between

I'm confuse.

Maybe someone would know.

Thanks




Lonnie Johnson
ProDev, Professional Development of MS Access Databases
http://www.prodev.us
Let me build your next MS Access database application. 




 



---------------------------------
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
Message #3 by Howard Henderson <howardh@o...> on Fri, 14 Mar 2003 09:55:32 -0600
How about -

iif([field1]=0,"Good", iif([field1]=1, "Bad", "Medium"))

My syntax may be a little off, but you get the idea...


Hope this helps,
Howard H.

-----Original Message-----
From: Joseph Valdez [mailto:e-valdez@a...]
Sent: Friday, March 14, 2003 11:38 AM
To: Access
Subject: [access] IIF statement


How would you write an IIF statement if you have three choices instead of
two.

For example: field values are: 0,1,2

I thought IIF is only for two choices or am I misunderstood its usage. as

IIF([field1]=0, "Good","BAD")
 Here I knew that if field1 = 0 it is good otherwise it is 1 which is bad.

Question is how about 2? which is in between

I'm confuse.

Maybe someone would know.

Thanks



Message #4 by Martyn Clark <martyn.clark@t...> on Fri, 14 Mar 2003 15:56:33 -0000
Joseph,

As Lonnie has suggested you could nest your IIF statements .... this is a
perfectly reasonable solution but could suffer from the drawback of being
difficult to read.

You could alternatively use the Select Case construct ....

Dim Number
Number = 2	' Initialize variable.

Select Case Number	' Evaluate Number.

	Case 0
		Debug.Print "Good"
	Case 1
		Debug.Print "Bad"
	Case Else
		Debug.Print "Undecided"

End Select

..... which might be easier to read. Typically you might use this for more
than three options.

Martyn

-----Original Message-----
From: Joseph Valdez [mailto:e-valdez@a...]
Sent: 14 March 2003 17:38
To: Access
Subject: [access] IIF statement


How would you write an IIF statement if you have three choices instead of
two.

For example: field values are: 0,1,2

I thought IIF is only for two choices or am I misunderstood its usage. as

IIF([field1]=0, "Good","BAD")
 Here I knew that if field1 = 0 it is good otherwise it is 1 which is bad.

Question is how about 2? which is in between

I'm confuse.

Maybe someone would know.

Thanks


The contents of this e-mail are strictly confidential and are intended only
for the addressee named above. This e-mail may contain confidential or
privileged information. If you are not the intended recipient of this
message please notify the sender immediately. The contents of this e-mail
must not be disclosed to any other person or copies taken. Please note that
any views expressed in this e-mail may be those of the originator and do not
necessarily reflect those of this organisation. Internet e-mail is not a
secure communications medium. Please note this lack of security when
responding by e-mail. Accordingly we give no warranties or assurances about
the security and content of this e-mail and its attachments. Neither Thermo
Electron Corporation nor the sender accepts any responsibility or liability
for viruses and it is your responsibility to scan the e-mail and
attachments. Any liability arising from any third party acting on any
information contained in this e-mail is hereby excluded.          (c) Thermo
Electron Corporation www.thermo.com
Message #5 by "Charlie Goodwin" <cgoodwin@c...> on Fri, 14 Mar 2003 13:38:39 -0500
Another option is the switch function

kinda klunky, but useful.

from MSft:

Switch Function Example
This example uses the Switch function to return the name of a language that
 matches the name of a city.

Function MatchUp (CityName As String)
    Matchup =3D Switch(CityName =3D "London", "English", CityName _
                    =3D "Rome", "Italian", CityName =3D "Paris", "French")
End Function

Charlie








> Joseph,
>
> As Lonnie has suggested you could nest your IIF statements .... this is a
> perfectly reasonable solution but could suffer from the drawback of being
> difficult to read.
>
> You could alternatively use the Select Case construct ....
>
> Dim Number
> Number =3D 2	' Initialize variable.
>
> Select Case Number	' Evaluate Number.
>
> 	Case 0
> 		Debug.Print "Good"
> 	Case 1
> 		Debug.Print "Bad"
> 	Case Else
> 		Debug.Print "Undecided"
>
> End Select
>
> ..... which might be easier to read. Typically you might use this for more
> than three options.
>
> Martyn
>
> -----Original Message-----
> From: Joseph Valdez [mailto:e-valdez@a...] [mailto:e-valdez@a...
m]]
> Sent: 14 March 2003 17:38
> To: Access
> Subject: [access] IIF statement
>
>
> How would you write an IIF statement if you have three choices instead of
> two.
>
> For example: field values are: 0,1,2
>
> I thought IIF is only for two choices or am I misunderstood its usage. as
>
> IIF([field1]=3D0, "Good","BAD")
>  Here I knew that if field1 =3D 0 it is good otherwise it is 1 which is b
ad.
>
> Question is how about 2? which is in between
>
> I'm confuse.
>
> Maybe someone would know.
>
> Thanks
>
>
> The contents of this e-mail are strictly confidential and are intended on
ly
> for the addressee named above. This e-mail may contain confidential or
> privileged information. If you are not the intended recipient of this
> message please notify the sender immediately. The contents of this e-mail
> must not be disclosed to any other person or copies taken. Please note th
at
> any views expressed in this e-mail may be those of the originator and do 
not
> necessarily reflect those of this organisation. Internet e-mail is not a
> secure communications medium. Please note this lack of security when
> responding by e-mail. Accordingly we give no warranties or assurances abo
ut
> the security and content of this e-mail and its attachments. Neither Ther
mo
> Electron Corporation nor the sender accepts any responsibility or liabili
ty
> for viruses and it is your responsibility to scan the e-mail and
> attachments. Any liability arising from any third party acting on any
> information contained in this e-mail is hereby excluded.          (c) The
rmo
> Electron Corporation www.thermo.com
>
Message #6 by "Steve Klein" <Stephen@K...> on Fri, 14 Mar 2003 21:23:32 -0000
probably the best way is to write a function using the select case approach.



If you must use iif :  iif ([txtName] = option1,"firstOption",iif([txtName]
= option2,"secondOption","ThirdOption"))
Steve K


-----Original Message-----
From: Joseph Valdez [mailto:e-valdez@a...]
Sent: 14 March 2003 17:38
To: Access
Subject: [access] IIF statement


How would you write an IIF statement if you have three choices instead of
two.

For example: field values are: 0,1,2

I thought IIF is only for two choices or am I misunderstood its usage. as

IIF([field1]=0, "Good","BAD")
 Here I knew that if field1 = 0 it is good otherwise it is 1 which is bad.

Question is how about 2? which is in between

I'm confuse.

Maybe someone would know.

Thanks




  Return to Index