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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIf statement sometimes works



 
 
Thread Tools Display Modes
  #1  
Old April 20th, 2010, 01:27 PM posted to microsoft.public.access.forms
Donna
external usenet poster
 
Posts: 565
Default IIf statement sometimes works

I have the following IIf statement on an unbound field on a form:

=IIf([Loaned/Out]="0"," ","Out of Service - Please Exit and select another
Vehicle")

Sometimes it comes back with the correct "Out of Service..." or nothing if
the vehicle is not designated as loaned/out, but other times it comes back
with "#NAME?".

Why is it not consistent? Thanks.
--
Donna N.
  #2  
Old April 20th, 2010, 01:47 PM posted to microsoft.public.access.forms
Golfinray
external usenet poster
 
Posts: 1,597
Default IIf statement sometimes works

1. If [loaned/out] is ever null you will get #name#. 2. Is [loaned/out] ever
not equal to "0"? Is "0" text or a number? If it is a number, you don't need
the quotes.
--
Milton Purdy
ACCESS
State of Arkansas


"Donna" wrote:

I have the following IIf statement on an unbound field on a form:

=IIf([Loaned/Out]="0"," ","Out of Service - Please Exit and select another
Vehicle")

Sometimes it comes back with the correct "Out of Service..." or nothing if
the vehicle is not designated as loaned/out, but other times it comes back
with "#NAME?".

Why is it not consistent? Thanks.
--
Donna N.

  #3  
Old April 21st, 2010, 03:27 PM posted to microsoft.public.access.forms
Donna
external usenet poster
 
Posts: 565
Default IIf statement sometimes works

Golfinray:

Thanks for the info. In the table, it is a Yes/No check box. I could not
get the IIf statement to work using "YES" or "NO", so I went with "0" = NO
and "-1" = YES because it would then run the statement correctly when I had
the check box selected. Am I assuming something that is not correct?

Thanks.
--
Donna N.


"Donna" wrote:

I have the following IIf statement on an unbound field on a form:

=IIf([Loaned/Out]="0"," ","Out of Service - Please Exit and select another
Vehicle")

Sometimes it comes back with the correct "Out of Service..." or nothing if
the vehicle is not designated as loaned/out, but other times it comes back
with "#NAME?".

Why is it not consistent? Thanks.
--
Donna N.

  #4  
Old April 21st, 2010, 04:14 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default IIf statement sometimes works

On Wed, 21 Apr 2010 07:27:01 -0700, Donna
wrote:

Golfinray:

Thanks for the info. In the table, it is a Yes/No check box. I could not
get the IIf statement to work using "YES" or "NO", so I went with "0" = NO
and "-1" = YES because it would then run the statement correctly when I had
the check box selected. Am I assuming something that is not correct?


A Yes/No field in a table - however it's formatted or displayed - is indeed
stored as a Number, 0 for No, -1 for Yes.

Comparing a -1 to a text string "Yes", or even to a text string "-1" (note the
quotes!) won't give the desired result. However, there are SQL defined
constants Yes and No (no quotes) which are equal to -1 and 0.

In an IIF statement, remember that the first argument to IIF is an expression
which evaluates to True or False. You may be able to just use the yes/no field
itself:

IIF([yesnofield], "value if yes", "value if no")

will work and you won't need any comparison operator.
--

John W. Vinson [MVP]
 




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:03 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.