Results 1 to 5 of 5

Thread: iif null error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    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 ??

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Location
    Sydney,NSW,Australia
    Posts
    178

    Post

    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

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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
    [email protected]
    [email protected]

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    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!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241

    Post

    Thanks Aaron ... I was wondering why it did that....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width