When Null field = Null field, the results are FALSE?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dowlingm815
    New Member
    • Feb 2010
    • 133

    When Null field = Null field, the results are FALSE?

    When testing the following code, the results should be true, however, a false results is generated. I don't understand why and i need to maintain the data values.

    Code:
         If strTEMP_CORD_No = rstTemp!CORD_No Then
                strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
            Else
                MsgBox "cord no not equal"
            End If
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You have to use the IsNull or Nz functions if you want to compare nulls. Null fields can be anything, so they never match each other in a binary comparison. Which is what the = binary comparison operator does.

    Comment

    • dowlingm815
      New Member
      • Feb 2010
      • 133

      #3
      i modified the code using the IsNull in the following matter.

      Code:
           If IsNull(strTEMP_CORD_No) Then
                  If IsNull(rstTemp!CORD_No) Then
                          strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
                  End If
              Else
                  If strTEMP_CORD_No = rstTemp!CORD_No Then
                      strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
                  End If
              End If

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You could also use Nz
        Code:
        If Nz(Field1, "") = Nz(Field2, "") Then
           ' Do something
        End If

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32656

          #5
          Is this a serious question?

          You are asking why the result of comparing one entirely unspecified value with another equally unspecified value doesn't return a True result when you expect it to. Good luck with that.

          Comment

          Working...