469,341 Members | 6,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

Validation If Null and Empty String

Are the following two validation the same:
1) IsNull(Me.ColumnName) and Me.ColumnName = ""
2) Me.ColumnName """

It would seem to be better to use: Me.ColumnName """

Feb 23 '07 #1
7 61976
On Feb 23, 3:06 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Are the following two validation the same:
1) IsNull(Me.ColumnName) and Me.ColumnName = ""
2) Me.ColumnName """

It would seem to be better to use: Me.ColumnName """
No they are not. One tests for a value (empty strings are values) and
the other sees what of two values is logically greater.
An empty string is less than a 'normal' string and a numeric variable
with no value defaults to 0.
However when doing this and one of the values is Null (mainly when
using variants) the comparison will always fail because a null has no
value to test.

I find the easiest test when you need to know if something is null is
to use the Nz function. If it is, this function lets you force a
different value so that your comparison don't fail.

Feb 23 '07 #2
On Feb 23, 2:23 pm, "storrboy" <storr...@sympatico.cawrote:
On Feb 23, 3:06 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Are the following two validation the same:
1) IsNull(Me.ColumnName) and Me.ColumnName = ""
2) Me.ColumnName """
It would seem to be better to use: Me.ColumnName """

No they are not. One tests for a value (empty strings are values) and
the other sees what of two values is logically greater.
An empty string is less than a 'normal' string and a numeric variable
with no value defaults to 0.
However when doing this and one of the values is Null (mainly when
using variants) the comparison will always fail because a null has no
value to test.

I find the easiest test when you need to know if something is null is
to use the Nz function. If it is, this function lets you force a
different value so that your comparison don't fail.
What is the recommended syntax to verify if a text box is empty?
I assume you should check for both nulls and empty string.
Does Me.Column "" check for both nulls and empty string?

Feb 23 '07 #3

If Nz(Me!txBoxName,True) Then
or
If Nz(Me!txBoxName,"") = "" then ....
or
variable = Nz(Me!txBoxName,"")

The last argument is what to return if the value is null. Otherwise
the actual value is returned.

Feb 23 '07 #4
On 23 Feb 2007 12:31:53 -0800, "to*******@msn.com" <to*******@msn.comwrote:
>On Feb 23, 2:23 pm, "storrboy" <storr...@sympatico.cawrote:
>On Feb 23, 3:06 pm, "tomleb...@msn.com" <tomleb...@msn.comwrote:
Are the following two validation the same:
1) IsNull(Me.ColumnName) and Me.ColumnName = ""
2) Me.ColumnName """
It would seem to be better to use: Me.ColumnName """

No they are not. One tests for a value (empty strings are values) and
the other sees what of two values is logically greater.
An empty string is less than a 'normal' string and a numeric variable
with no value defaults to 0.
However when doing this and one of the values is Null (mainly when
using variants) the comparison will always fail because a null has no
value to test.

I find the easiest test when you need to know if something is null is
to use the Nz function. If it is, this function lets you force a
different value so that your comparison don't fail.

What is the recommended syntax to verify if a text box is empty?
I assume you should check for both nulls and empty string.
Does Me.Column "" check for both nulls and empty string?
If Len(Me.MyTextBox & "") 0 Then ...

This will catch both Nulls and ZeroLengthStrings in one check.
Wayne Gillespie
Gosford NSW Australia
Feb 24 '07 #5
I use the following code to check for null and empty string:

If Len(Nz(Me!txBoxName,"")) = 0 Then

Feb 24 '07 #6
PrettyCool Wayne!
I hadn't seen that one yet. All with one function

Feb 24 '07 #7
On 23 Feb 2007 16:42:13 -0800, "Ap******@gmail.com" <Ap******@gmail.comwrote:
>PrettyCool Wayne!
I hadn't seen that one yet. All with one function
I think I got it from Lyle from memory.
Wayne Gillespie
Gosford NSW Australia
Feb 24 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by David Graham | last post: by
7 posts views Thread by BlueDragon | last post: by
4 posts views Thread by web1110 | last post: by
26 posts views Thread by Neville Lang | last post: by
6 posts views Thread by =?Utf-8?B?QmlsbEF0V29yaw==?= | last post: by
8 posts views Thread by Joe Kovac | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.