I think I will do what I can to avoid tests for Null. If you always
assign a default value to a field or control before the user does
anything with it, then I believe it shouldn't be necessary to ever use
a Null test.
You probably won't be able to get away with this, I'm afraid: and it's
partly Access's fault and it's partly Jet.
Most databases will allow text fields to have a value ("Eric") or a NULL,
but Jet muddies the water slightly with the AllowZeroLength property, which
allows the inbetween value "". There are certainly situations where this is
appropriate, but it does confuse matters.
Now the kicker. Access text boxes will RTRIM all values before returning
them, so that if you enter "Me ", you'll get back "Me". To make things
worse, it will convert "" to NULL, so that if you enter " ", you won't
get "" but NULL. There is nothing you can do about this behaviour[1], I'm
afraid. The advantage of this is that when you use numeric or date fields,
they get the legal value of NULL, whereas "" is not a valid date or number.
Compare this to Visual Basic, where an empty text box returns "", and this
value has to intercepted before it causes hundreds of Data Type errors if
it gets posted to a numeric or date field.
As I said above, however, Jet itself is quite happy with "" or " " in text
fields: you can check this with
UPDATE MyTable SET MyText = " " WHERE ID = 1023;
then
SELECT Len(MyText) FROM MyTable WHERE ID = 1023;
or
SELECT MyText IS NULL FROM MyTable WHERE ID = 1023;
and you get the right answers. It's just the Access forms getting in the
way.
The bottom lines are, then:
1) always use Variants to pass field values to and from;
2) check them with IsNull before assuming they hold a value;
3) take an _explicit_ decision about the meaning of 0, NULL and ""
[1] You can work round it, though, if you really want a "" in a text field:
Private Sub MyText_BeforeUpdate(Cancel as Integer)
' this is the control, use dot
If IsNull(Me.MyText.Value) Then
' this is the field, use bang
Me!MyText = ""
End If
End Sub
but only if you really, really, really NEED it!
Hope it helps
Tim F