Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IIf Function doesn't work properly

Status
Not open for further replies.

Blex

Programmer
Nov 19, 2002
2
NL
I have the following criterium in an select query:

IIf(IsLoaded("FView Records");[Forms]![FView Records]![Material_nr];[Forms]![FView Specification]![NrField])

What I want to do is check with the IsLoaded function if the form "FView Recorrds" is loaded. If so, the IIf function should return a value of the "FView Records" form and otherwise it should return a value of the "FView Specification" form.

The problem is, when I run this, the IIf function does ask for both True and False functions. The function only uses one of the values, but it asks for both values. And I don't want that.

Can anybody help me with this problem?
 
I am assuming that IsLoaded sends back a Boolean. I do not believe I have ever used semicolon as a separator in the function. When I tested the use of semicolons, I received an error. I use a comma to separate the expressions.

IIf(IsLoaded("FView Records");[Forms]![FView Records]![Material_nr];[Forms]![FView Specification]![NrField])

The IIF function is a Ternary Operator.
expression1 ? expression2 : expression3

If the first expression evaluates to true, the second expression is used, else the third expression is used.
 
Just so you both know - I understood that IIF evaluates both outputs NO MATTER WHAT. Which can be annoying in code if one is null...


Vince
 
Vince,
I ment not offence. Sorry that I misunderstood the question.
Dalton
 
does the iif use the semicolon or a comma? I always use the comma.

rollie@bwsys.net
 
from what I know IIF IS FOR CONTROLS ONLY
if you want to use it in code then go with
IF... THEN ...statements REGARDS, KUZZ

LIFE IS GREAT WHEN THERE IS SOMEONE TO HELP YOU.
DESIGNING DATABASES SINCE 2002
 
iif is also used in code

try

dim ansr as string , ok as boolean

ok = true

ansr = iif( oka, "I am true", "I am false")

msgbox ansr

ok = false
ansr = iif( oka, "I am true", "I am false")

msgbox ansr

rollie@bwsys.net
 
It's true that you should use commas to separate parameters. It's true that iif can be used in code. It's true that iif evaluates both the true part and the false part, so both parts have to be legit, no matter what the outcome of the test part is.

If this is in code, break it out using an if/then/else structure.

If not...well let us know if this isn't in code and we'll cross that bridge if we need to.

Jeremy

=============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.
 
Hahahahaha REGARDS, KUZZ

LIFE IS GREAT WHEN THERE IS SOMEONE TO HELP YOU.
DESIGNING DATABASES SINCE 2002
 
I want to thank you guys for all your hints and tips. Visual Basic doesn't seem to need both outputs with the If..Then..Else structure, so I've made a function with that structure and now it works properly!
Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top