473,653 Members | 2,972 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 63105
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
23382
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 posts on form validation. It all centers around whether I am interpreting an empty string correctly -...
7
5541
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 forgot to ask. A zero length string, however, tells me HR did ask and there is no middle name....
8
10403
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 corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
5
2447
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
2344
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
3796
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
37159
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
4766
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, e.g. exchange "30" by "00:30".
2
14183
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? The bcp command I used to export table into csv file is bcp "SELECT...
0
8370
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8704
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
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

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.