Problem with IIf Statement

T

Tony Williams

Could anyone tell me why this statement doesn't work?
=IIf(IsNull([txtfname]) And IsNull([txtsubjectcompany]),"Unknown",[txtfname]
& [txtsubjectcompany])

Basically I have a control that needs to say Unknown if 2 other controls are
null.
Thanks
Tony
 
B

bcap

What do you mean by "doesn't work"? Does it display #Error? Or #Name? Or
an incorrect value? Or what?
 
J

Jim Bunton

Use the query builder to create a query like!
SELECT txtfname, txtsubjectcompany, IIf(IsNull([txtfname]) And
IsNull([txtsubjectcompany]),"Unknown, "Known") AS YourOwnSuitableName FROM
TheAppropriateTableOrQuery
WHERE whatever
ORDER BY whatever
etc!
Hack it about 'til it works ok
Make this the query for the form then use YourOwnSuitableNameas the value
for the contral.

Might help!

Jim Bunton
 
B

Beetle

I don't see anything wrong with the statement itself (I just tested it
and it works on my end), so maybe your controls/fields are zero
length strings (rather than Null). You might try;

=IIf(Nz([txtfname], "")="" And Nz([txtsubjectcompany],
"")="","Unknown",[txtfname] & [txtsubjectcompany])
 
T

Tony Williams

Thanks Sean that's correct
Tony

Beetle said:
I don't see anything wrong with the statement itself (I just tested it
and it works on my end), so maybe your controls/fields are zero
length strings (rather than Null). You might try;

=IIf(Nz([txtfname], "")="" And Nz([txtsubjectcompany],
"")="","Unknown",[txtfname] & [txtsubjectcompany])

--
_________

Sean Bailey


Tony Williams said:
Could anyone tell me why this statement doesn't work?
=IIf(IsNull([txtfname]) And IsNull([txtsubjectcompany]),"Unknown",[txtfname]
& [txtsubjectcompany])

Basically I have a control that needs to say Unknown if 2 other controls are
null.
Thanks
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with IIF statment 6
IIf function Problem 4
Always returns the same number? 8
IIf Statement in Subform Query 1
IIF Statement Help 7
SQL Problem 2
Help with IIf statement 9
Problem with IIF statement 5

Top