A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIF STATEMENT



 
 
Thread Tools Display Modes
  #1  
Old May 8th, 2010, 01:18 AM posted to microsoft.public.access.queries
gambler
external usenet poster
 
Posts: 13
Default IIF STATEMENT

When i write the following IIF statement i get the error mesage WRONG #
ARGUMENTS. What am i doing wrong?
K:IIF([PL5HX4.RK]=1,2,0IIF([PL5HX4.RK]=2,1,0))
tHANKS
ED
  #2  
Old May 8th, 2010, 01:34 AM posted to microsoft.public.access.queries
Duane Hookom
external usenet poster
 
Posts: 7,177
Default IIF STATEMENT

It looks like you have an extra 0 in there. This seems like unusual
bracketing of the table and field name.
K:IIF([PL5HX4].[RK]=1,2,IIF([PL5HX4].[RK]=2,1,0))

You could rewrite this as the following if the possible values for RK as
1,2, or 3.
K:Choose([PL5HX4].[RK],2,1,0)

--
Duane Hookom
Microsoft Access MVP


"gambler" wrote:

When i write the following IIF statement i get the error mesage WRONG #
ARGUMENTS. What am i doing wrong?
K:IIF([PL5HX4.RK]=1,2,0IIF([PL5HX4.RK]=2,1,0))
tHANKS
ED

  #3  
Old May 8th, 2010, 02:01 AM posted to microsoft.public.access.queries
gambler
external usenet poster
 
Posts: 13
Default IIF STATEMENT

My table is ALL_HX4
I wrote a query PL5HX4. tHIS IS WHERE rk is located.
Then i wrote another query LU. It is in here that i put my iif statement.
Your suggestion didnt work.
If i write the IIf sattement as K:IIF([PL5HX4.RK]=1,2)iT WORKS
When i write it and include the second IIF statement it fails. Hope i
explained myself clearly. If not please let me know.
Thanks Duane
ed

"Duane Hookom" wrote:

It looks like you have an extra 0 in there. This seems like unusual
bracketing of the table and field name.
K:IIF([PL5HX4].[RK]=1,2,IIF([PL5HX4].[RK]=2,1,0))

You could rewrite this as the following if the possible values for RK as
1,2, or 3.
K:Choose([PL5HX4].[RK],2,1,0)

--
Duane Hookom
Microsoft Access MVP


"gambler" wrote:

When i write the following IIF statement i get the error mesage WRONG #
ARGUMENTS. What am i doing wrong?
K:IIF([PL5HX4.RK]=1,2,0IIF([PL5HX4.RK]=2,1,0))
tHANKS
ED

  #4  
Old May 8th, 2010, 04:32 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default IIF STATEMENT

We are not looking over your shoulder at your computer screen. Please try
and describe your symptoms without using generic, meaningless terms like
"fails" and "didn't work". What happened when you tried Duane's suggestion?
Error message? What was it?
Incorrect results? Try and explain what was wrong with them. If you need to,
show examples of the data, followed by what the result of Duane's suggestion
was, followed by what you want the result to look like.

gambler wrote:
My table is ALL_HX4
I wrote a query PL5HX4. tHIS IS WHERE rk is located.
Then i wrote another query LU. It is in here that i put my iif
statement. Your suggestion didnt work.
If i write the IIf sattement as K:IIF([PL5HX4.RK]=1,2)iT WORKS


Impossible. The IIF() function requires 3 arguments and you've only supplied
2.

When i write it and include the second IIF statement it fails. Hope i
explained myself clearly. If not please let me know.
Thanks Duane
ed

"Duane Hookom" wrote:

It looks like you have an extra 0 in there. This seems like unusual
bracketing of the table and field name.
K:IIF([PL5HX4].[RK]=1,2,IIF([PL5HX4].[RK]=2,1,0))

You could rewrite this as the following if the possible values for
RK as 1,2, or 3.
K:Choose([PL5HX4].[RK],2,1,0)

--
Duane Hookom
Microsoft Access MVP


"gambler" wrote:

When i write the following IIF statement i get the error mesage
WRONG # ARGUMENTS. What am i doing wrong?
K:IIF([PL5HX4.RK]=1,2,0IIF([PL5HX4.RK]=2,1,0))
tHANKS
ED


--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #5  
Old May 10th, 2010, 06:36 AM posted to microsoft.public.access.queries
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default IIF STATEMENT

"Bob Barrows" wrote in message
...

Impossible. The IIF() function requires 3 arguments and you've only
supplied 2.



Quite possible, actually. While the VBA IIf() function requires all 3
arguments, the JET SQL IIf() function does not. In a query, it's the SQL
version of the function that will be used, not the VBA function of the same
name.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

  #6  
Old May 10th, 2010, 12:12 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default IIF STATEMENT

Dirk Goldgar wrote:
"Bob Barrows" wrote in message
...

Impossible. The IIF() function requires 3 arguments and you've only
supplied 2.



Quite possible, actually. While the VBA IIf() function requires all 3
arguments, the JET SQL IIf() function does not. In a query, it's the
SQL version of the function that will be used, not the VBA function
of the same name.


Learn something new every day, I guess. I always assumed it was using the
VBA function and never realized there was a JetSQL version.

I assume it returns Null if the test expression fails and no false result is
supplied ...
--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


  #7  
Old May 10th, 2010, 06:07 PM posted to microsoft.public.access.queries
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default IIF STATEMENT

"Bob Barrows" wrote in message
...

Learn something new every day, I guess. I always assumed it was using the
VBA function and never realized there was a JetSQL version.


There are just a couple of VBA functions that have native JetSQL functions
with the same name (and slightly different characteristics). I believe Nz()
is another, but I'm not 100% sure.

The Jet IIf() function is different in another way: the VBA function always
evaluates both the "return-if-True" operand and the "return-if-False"
operand, while the Jet version only evaluates the argument that is going to
be returned.

I assume it returns Null if the test expression fails and no false result
is supplied ...


Quite right.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.