Results 1 to 4 of 4

Thread: Detecting NULL in recordset

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98
    Hi guys,

    How do i detect NULLs in a recordset. forexample:

    rst.fields("date").value is actually a null (empty field due to various reasons).

    the following simple if else statement cannot do the detection.

    if rst.fields("date").value=null then
    end sub
    else
    'carry on with routine
    endif

    Pls advice.

  2. #2
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    Use the IsNull() function. For example:

    Code:
    -------------------------------
    If IsNull(rst.Fields("Date")) Then Exit Sub

    'Or better (if you want to retrieve a nonnull value for the field):

    strVal=IIf(IsNull(rst.Fields("Date")),"",rst.Fields("Date"))
    -------------------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98
    Thanks!
    Can u explain more on the IIF function?

  4. #4
    Addicted Member
    Join Date
    Sep 2000
    Posts
    138
    The IIf() function is used to test for a condition. If the condition is true then it returns the first value (in the case of my suggested code, the "") or it returns the second value (in the case of my code, the value in the field rst.Field("Date")). That is to say, the IIf() function in my code tests your field "Date". If the field is null, it returns a "" (to be stored in strVal); if it is not null, it returns the value held in that field.

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