PDA

Click to See Complete Forum and Search --> : iif null error


David Laplante
Nov 23rd, 1999, 03:08 AM
I have this line of code:
ItemListe.SubItems(1) = IIf(Not IsNull(rstRechercheClient!Client_Telephone1), IIf(Not IsNull(rstRechercheClient!FormatPays_Telephone), Format(rstRechercheClient!Client_Telephone1, rstRechercheClient!FormatPays_Telephone), rstRechercheClient!Client_Telephone1), "")

(A little confusing maybe but hey...)
now my problem is that both fiels from my recordset (rstRechercheClient) are NULL... when I get to this line I get a : INVALID USE OF NULL error...
I thought the NOT ISNULL syntax was supposed to avoid that.... what is my problem here ??

jritchie
Nov 23rd, 1999, 03:13 AM
David,

How about trying something like

itemlist.subitems(1) = "" & rstRe......
or
if you need formating

....= "" & format(rstRe....,"format code")

or

if don't want to load if null

if len(trim(rstRe...)) > 0 then
itemlist.subitems(1) = ....
end if

Hope this helps

Aaron Young
Nov 23rd, 1999, 03:19 AM
The problem with the IIF Statement is that it validates/evaluates both True and False Arguments regardless of the Result, eg.

Debug.Print IIF(1 = 1, 5 + 5, 10 + 10)

Even though this would always Display 10, it still checks and evaluates 10 + 10.

So even though you check for Nulls in the Expression Part, it still tries to use the Null Value when Validating the False Parameter of your IIF Statement.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

David Laplante
Nov 23rd, 1999, 03:31 AM
Thanks a lot jritchie it's A GREAT idea.... tried it. It works just fine and it's even faster because you can get rid of the IIF's...

Thanks a lot!

David Laplante
Nov 23rd, 1999, 03:33 AM
Thanks Aaron ... I was wondering why it did that....