Results 1 to 4 of 4
  1. #1
    PatriciaWilliams
    Guest

    Speaking of Nulls

    [img]/w3timages/icons/hairy.gif[/img]
    Usually I use the "isnull()" function in my VBA code to find out if something is null, but I slipped up and used the following construct: "if (expression) = Null then". I went into debug mode to see why I kept getting null errors, when I thought I had put in that preventative step. The code stepped right on through the line without twinging, but was also not evaluating (what I thought I had asked it to do!). I often use the "if (expression) = 5 then " construct, but it appears that the "=" does not work with the Null. It perhaps could have worked fine with "if (expression) IS Null then ".
    Is there any definitave literature out there saying if/when isnull() is better than (something) IS Null, and/or why the "=" construct won't work for Null?
    thx
    Pat

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Speaking of Nulls

    Hi Patricia,

    A Null value is indicating that the data is missing. In that case there is no data!
    That is the reason you cannot use the = sign.
    You can use if (expression) IS Null or the function IsNull(). I never noticed any difference in using them. Using the function gives you in most cases a better readability of your code.

  3. #3
    PatriciaWilliams
    Guest

    Re: Speaking of Nulls

    > A Null value is indicating that the data is missing. In that case there is no data!
    > That is the reason you cannot use the = sign.

    .......... That makes _too_ much sense! <gg>

    > I never noticed any difference in using them. Using the function gives you in most cases a better readability of your code.

    ......... I usually use the function, but in this case, I guess what caused me to go off-track was that I had quite a large expression on the left, and I didn't want to add another element by surrounding it with an isnull(). I agree with you that it is usually very readible to use the isnull() function.

    ........... Thanks for your response!

    Pat

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Speaking of Nulls

    Any comparison with a null on one side will always return a false because you can't compare something to nothing![img]/w3timages/icons/grin.gif[/img]
    Charlotte

Posting Permissions

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