Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vba understanding (97nl)

    Hello all,

    Could someone tell me why example 1 does not work and example 2 will work:

    example 1
    -----------------------------------
    If numPrio = 0 Then
    If datD1 = Null Then
    datDeadline = datHD
    Else
    datDeadline = datD1
    End If
    Else
    datDeadline = datD2
    End If
    -----------------------------------

    example 2
    -----------------------------------
    If numPrio = 0 And datD1 = Null Then datDeadline = datHD
    If numPrio = 0 And datD1 = Null Then datDeadline = datD1
    If numPrio <> 0 Then datDeadline = datD2
    -----------------------------------

    They seem the same to me, but they word different
    Thanks in advance.

  2. #2
    2 Star Lounger
    Join Date
    Apr 2002
    Location
    Amersfoort, Utrecht, Netherlands
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: vba understanding (97nl)

    Great Hans,

    Thanks, I understand the problem now

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: vba understanding (97nl)

    Perhaps you didn't copy Example 2 correctly: it contains "If numPrio = 0 And datD1 = Null Then" twice.

    In fact, both code samples are incorrect. You cannot compare a value to Null by testing "If ... = Null Then", since Null is not really a value, it indicates the lack of a value. Use the IsNull function instead:

    If NumPrio = 0 Then
    If IsNull(datD1) Then
    datDeadline = datHD
    Else
    datDeadline = datD1
    End If
    Else
    datHeadline = datD2
    End If

    Even shorter is the use of the Access-specific Nz function:

    If NumPrio = 0 Then
    datDeadline = Nz(datD1, datHD)
    Else
    datHeadline = datD2
    End If

    Nz returrns the first argument, unless that is Null, then it returns the second argument.

Posting Permissions

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