473,554 Members | 2,919 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation If Null and Empty String

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

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

Feb 23 '07 #1
7 63087
On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
Are the following two validation the same:
1) IsNull(Me.Colum nName) 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...@sympa tico.cawrote:
On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
Are the following two validation the same:
1) IsNull(Me.Colum nName) 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...@sympa tico.cawrote:
>On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
Are the following two validation the same:
1) IsNull(Me.Colum nName) 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.MyTextBo x & "") 0 Then ...

This will catch both Nulls and ZeroLengthStrin gs 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!txBox Name,"")) = 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
23369
by: David Graham | last post by:
Hi I have been busy going through the last weeks postings in an attempt to absorb javascript syntax (I guess it's not possible to just absorb this stuff in a passive way - I'm getting way out of my depth with most of the posts, I will buy a good book and take some online tutorials) Anyway, I think I almost understand one of Mr Nielsen's...
7
5537
by: BlueDragon | last post by:
I don't know enough math to demonstrate that any numerical operation with a null should yield a null; although I would guess that it's true. I just don't buy it, however, when dealing with strings and nulls. In a simple table with first, middle and last name columns, I would infer that a null value in the middle name column means the HR person...
8
10396
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or...
5
2443
by: VMI | last post by:
How can I validate a null string or an empty string in the same IF statement? If I use this: if (myString.Trim().Length <= 0 || myString == null) { //do stuff } I'll get a run-time error because I can't trim (or get the length) of a Null
4
2339
by: web1110 | last post by:
I have an array of of 5 string elements. I put values in 3 of them. Yet when I loop over them, I do not catch the empty string. The code output below does not include "Empty" stringx=new String; x="111"; x="222"; x="333";
26
3786
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
6
37152
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, Thought this would be simple! If I want to validate a field that can contain "z" followed by 3 digits OR it's a completely empty string, how do I do that? The z123 bit is simple, but the empty string is giving me problems! e.g. ^\d{3}$| ....doesn't work (I thought the trailing "|" would detect the empty string). Thanks.
8
4763
by: Joe Kovac | last post by:
Hi! I want the user to edit a textbox which allows following values only: - Time (Format: 23:59, HH:MM) or - NULL (empty string) What can I do, so that this works kinda automatically, meaning on the client side. It would be also nice, that not only errors would be detected, but also that "wanted error" would be corrected if possible,...
2
14171
by: Jay | last post by:
I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file? ...
0
7600
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7889
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6145
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5436
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5155
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2020
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
841
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.