How to express NULL or NOTHING IN THE box ?

M

Martin

I want to express the meaning of: if [Combo270] is with nothing in it,
then...
However, I wrote the VBA as follows, they all are wrong. How to do?


WRONG 1:

If [Forms]![abcMartininq]![Combo270] Is Null Then
........................

WRONG 2:

If [Forms]![abcMartininq]![Combo270]="" Then
........................


How to make a right VBA? Thanks!


Martin
 
K

Ken Snell [MVP]

I usually use this setup:

If Len([Forms]![abcMartininq]![Combo270] & "") = 0 Then
' the control is empty - either Null or an empty string


One can use the IsNull function to do the test, but note that an empty
string value will return False on this test:

If IsNull([Forms]![abcMartininq]![Combo270]) = True Then
' the control holds a Null value
 
D

Dirk Goldgar

Martin said:
I want to express the meaning of: if [Combo270] is with nothing in it,
then...
However, I wrote the VBA as follows, they all are wrong. How to do?


WRONG 1:

If [Forms]![abcMartininq]![Combo270] Is Null Then
.......................

WRONG 2:

If [Forms]![abcMartininq]![Combo270]="" Then
.......................


How to make a right VBA? Thanks!


Martin

You were close the first time. This will work if the control can't
contain a zero--length string, which is distinct from Null:

If IsNull([Forms]![abcMartininq]![Combo270]) Then

If the control might contain a zero-length string, then you can be
comprehensive and test for either Null or a ZLS in one go, like this:

If Len([Forms]![abcMartininq]![Combo270] & vbNullString) = 0 Then
 
M

Martin

You all help me a lot! :)

Mr. Dirk Goldgar,

I am always wondering why this null express ( ="" ) can't work in ACCESS: ?

If [Forms]![abcMartininq]![Combo270]=""
 
D

Dirk Goldgar

Martin said:
You all help me a lot! :)

Mr. Dirk Goldgar,

I am always wondering why this null express ( ="" ) can't work in
ACCESS: ?

If [Forms]![abcMartininq]![Combo270]=""

No one ever said it wouldn't work. It works fine. However, referring
to vbNullString is marginally more efficient -- and I mean it *really*
only makes a difference to the most compulsive programmer -- because it
uses a constant that is already defined, rather than forcing the VB
compiler to create a new one.
 
V

Van T. Dinh

"" is not Null. It is an empty String which is different from Null. You
see that "" is already defined as String type while Null has even got a
datype defined!.

HTH
Van T. Dinh
MVP (Access)
 
Top