When is Null not Null?

T

Tcs

Can anyone tell me why this doesn't work?

If DAOrs!OlCode1 = Null Then
DAOrs!OlCode1 = DAOrsC!OLADCC
DAOrs!OlDesc1 = DAOrsC!OLACDS
End If

According to VB, DAOrs!OlCode1 IS null, so the test should be true. But it
doesn't work. What am I doing wrong?

Thanks in advance,

Tom
 
W

Wayne Morgan

You can't do "=Null" because Null is the absence of a value so there is
nothing to be equal to. Instead try:

If IsNull(DAOrs!OlCode1) Then
 
S

Steve Schapel

Tom,

Null is an unknown value, so nothing can be = Null
Try it like this...

If IsNull(DAOrs!OlCode1) Then
DAOrs!OlCode1 = DAOrsC!OLADCC
DAOrs!OlDesc1 = DAOrsC!OLACDS
End If
 
F

fredg

Can anyone tell me why this doesn't work?

If DAOrs!OlCode1 = Null Then
DAOrs!OlCode1 = DAOrsC!OLADCC
DAOrs!OlDesc1 = DAOrsC!OLACDS
End If

According to VB, DAOrs!OlCode1 IS null, so the test should be true. But it
doesn't work. What am I doing wrong?

Thanks in advance,

Tom

Either:
If IsNull(DAOrs!OlCode1) Then
code here
End If
Or

If DAOrs!OlCode1 Is Null Then
code here
End If

but not = Null.
A field can't = Null but it can be Null.
 
E

el zorro

THis may be Much Ado About Null (heh heh), but I have
successfully used this code:

Forms!FormName!NumberField.Value = Null

I use it to wipe-out a previous entry when a related
field is changed. It works, but is this bad coding?
-----Original Message-----
Works great.

Thanks.
 
D

Douglas J. Steele

Your example involves setting a field's value to Null, and is fine.

The rest of the discussion is about trying to use the equal sign to do a
boolean comparison between a field's value and Null.

Some languages use a different symbol, so as not to confuse the two: = vs.
== or :=, for example.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



el zorro said:
THis may be Much Ado About Null (heh heh), but I have
successfully used this code:

Forms!FormName!NumberField.Value = Null

I use it to wipe-out a previous entry when a related
field is changed. It works, but is this bad coding?
 
J

John Vinson

THis may be Much Ado About Null (heh heh), but I have
successfully used this code:

Forms!FormName!NumberField.Value = Null

I use it to wipe-out a previous entry when a related
field is changed. It works, but is this bad coding?

This expression will indeed work correctly. You can't compare anything
to NULL, except with the IsNull() function, but you can safely set any
Variant (such as a form control's Value property) to NULL.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
E

el zorro

I wasn't clear on that distinction, but I see it now.
Thanks!
-----Original Message-----
Your example involves setting a field's value to Null, and is fine.

The rest of the discussion is about trying to use the equal sign to do a
boolean comparison between a field's value and Null.

Some languages use a different symbol, so as not to confuse the two: = vs.
== or :=, for example.
 
D

david epsom dot com dot au

This expression will indeed work correctly. You can't compare
to NULL, except with the IsNull() function, but you can safely

This is a VBA forum, so fair enough, but for any lurkers out
there, note that more generally there is a better way in SQL
(or in the expression evaluator):

instead of
IsNull(),
you can use
Is Null


for example:

If eval("null is null") then

or
"Select * from tbl where fld is Null;"

(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top