By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

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

100+
P: 133
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.

Expand|Select|Wrap|Line Numbers
  1.      If strTEMP_CORD_No = rstTemp!CORD_No Then
  2.             strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
  3.         Else
  4.             MsgBox "cord no not equal"
  5.         End If
  6.  
Mar 5 '12 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,315
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.
Mar 5 '12 #2

100+
P: 133
i modified the code using the IsNull in the following matter.

Expand|Select|Wrap|Line Numbers
  1.      If IsNull(strTEMP_CORD_No) Then
  2.             If IsNull(rstTemp!CORD_No) Then
  3.                     strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
  4.             End If
  5.         Else
  6.             If strTEMP_CORD_No = rstTemp!CORD_No Then
  7.                 strTEMP_BANNERPOAmt = strTEMP_BANNERPOAmt + rstTemp!BANNERPOAmt
  8.             End If
  9.         End If
  10.  
Mar 5 '12 #3

Rabbit
Expert Mod 10K+
P: 12,315
You could also use Nz
Expand|Select|Wrap|Line Numbers
  1. If Nz(Field1, "") = Nz(Field2, "") Then
  2.    ' Do something
  3. End If
Mar 5 '12 #4

NeoPa
Expert Mod 15k+
P: 31,186
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.
Mar 5 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.