Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in testing for Null in If-Else

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

Something wrong with testing for Null value?

==================================
If Cust_name = Null then

msgbox "No name!"
End if
====================================

Cannot work even i can be sure than Cust_name is Null
 
If IsNull(Cust_name) then

msgbox "No name!"
End if

or, to test for Null OR a zero-length string:

If Len(Nz(Cust_name, "")) = 0 Then
MsgBox "no name!"
End If

Dan
[pipe]
 
What you encountered is called "Null propagation". Microsoft introduced it as a feature, but I think it is a severe bug. It means that if Null is input to a function or even operator, Null is the output also.

So the '=' operator is NOT a boolean, but a variant:
Code:
Null = Null,
(Cust_name = Null) = Null
, not true, neither false!

But
Code:
if Null then...
is executed as
Code:
if False then...

Nicest problem:
Code:
(not false) = true
, but
Code:
(not Null)
remains
Code:
Null
...

That is why you need the
Code:
IsNull()
function

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top