A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Check if field is empty (what code to use)



 
 
Thread Tools Display Modes
  #1  
Old February 27th, 2010, 04:46 PM posted to microsoft.public.access
Lars Brownies[_2_]
external usenet poster
 
Posts: 157
Default Check if field is empty (what code to use)

In a form's BeforeUpdate I check if certain fields are empty, and if that's
the case I cancel the BeforeUpdate. I always use this kind of code for that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only way a
textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


  #2  
Old February 27th, 2010, 07:01 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Check if field is empty (what code to use)

Always take account of Murphy's Law. If a field or control can be Null or
contain a zero-length string, then, regardless of whether you think there is
no way a zero-length string can have been assigned to it, its prudent to test
for both, which your expression will do, as will the others, apart from
testing for Nothing, which refers to an unassigned object variable, so I'd
think would raise an error.

Ken Sheridan
Stafford, England

Lars Brownies wrote:
In a form's BeforeUpdate I check if certain fields are empty, and if that's
the case I cancel the BeforeUpdate. I always use this kind of code for that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only way a
textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201002/1

  #3  
Old February 27th, 2010, 07:58 PM posted to microsoft.public.access
Lars Brownies[_2_]
external usenet poster
 
Posts: 157
Default Check if field is empty (what code to use)

Thanks Ken.
I've been doing this "" check only for text boxes bound to text fields. Are
you saying I should also do this for text boxes bound to for instance
numeric or date fields?

Lars


"KenSheridan via AccessMonster.com" u51882@uwe schreef in bericht
news:a44597143429b@uwe...
Always take account of Murphy's Law. If a field or control can be Null or
contain a zero-length string, then, regardless of whether you think there
is
no way a zero-length string can have been assigned to it, its prudent to
test
for both, which your expression will do, as will the others, apart from
testing for Nothing, which refers to an unassigned object variable, so I'd
think would raise an error.

Ken Sheridan
Stafford, England

Lars Brownies wrote:
In a form's BeforeUpdate I check if certain fields are empty, and if
that's
the case I cancel the BeforeUpdate. I always use this kind of code for
that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only way
a
textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201002/1

  #4  
Old February 27th, 2010, 09:49 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Check if field is empty (what code to use)

No, only for fields of text data type. A date/time data type can only be a
true date/time value or Null; a field of number data type can only be a
number or Null; similarly with a currency data type, which is really just a
kind of number. With numbers or currency its always worth giving serious
consideration to whether the field should have a default value of zero or not.
With currency in particular I find that this is more often the case than not
due to the ambiguity of Null. As I've said here many times before, what does
a Null credit limit mean? No credit? Unlimited credit? There's no way of
knowing, its entirely a matter of interpretation. A zero credit limit is
unambiguous. Also you then don't have any problems with Nulls messing up
arithmetical calcaulations.

Ken Sheridan
Stafford, England

Lars Brownies wrote:
Thanks Ken.
I've been doing this "" check only for text boxes bound to text fields. Are
you saying I should also do this for text boxes bound to for instance
numeric or date fields?

Lars

Always take account of Murphy's Law. If a field or control can be Null or
contain a zero-length string, then, regardless of whether you think there

[quoted text clipped - 31 lines]

Lars


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201002/1

  #5  
Old February 27th, 2010, 10:06 PM posted to microsoft.public.access
Lars Brownies[_2_]
external usenet poster
 
Posts: 157
Default Check if field is empty (what code to use)

Thanks again.

Lars

"KenSheridan via AccessMonster.com" u51882@uwe schreef in bericht
news:a4470e594c461@uwe...
No, only for fields of text data type. A date/time data type can only be
a
true date/time value or Null; a field of number data type can only be a
number or Null; similarly with a currency data type, which is really just
a
kind of number. With numbers or currency its always worth giving serious
consideration to whether the field should have a default value of zero or
not.
With currency in particular I find that this is more often the case than
not
due to the ambiguity of Null. As I've said here many times before, what
does
a Null credit limit mean? No credit? Unlimited credit? There's no way
of
knowing, its entirely a matter of interpretation. A zero credit limit is
unambiguous. Also you then don't have any problems with Nulls messing up
arithmetical calcaulations.

Ken Sheridan
Stafford, England

Lars Brownies wrote:
Thanks Ken.
I've been doing this "" check only for text boxes bound to text fields.
Are
you saying I should also do this for text boxes bound to for instance
numeric or date fields?

Lars

Always take account of Murphy's Law. If a field or control can be Null
or
contain a zero-length string, then, regardless of whether you think
there

[quoted text clipped - 31 lines]

Lars


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/201002/1

  #6  
Old February 27th, 2010, 10:43 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Check if field is empty (what code to use)

I tend to use
IF Len([object] & "") = 0 Then
...

Why? a control or a field can can be null or have a value. Text objects can
have a zero-length string value (especially if tied to a field that allows
zero Length strings.

If the object is a number, date, etc then it can be null or have a value, so
you could just test for null.

I don't know if this is still true, but at one time the check for length was
quicker than other tests. It probably makes very little difference in terms
of efficiency given the speed of modern computers. I would think you would
have to be in a loop with hundreds of thousands of iterations to see any
perceived difference as a human.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Lars Brownies wrote:
In a form's BeforeUpdate I check if certain fields are empty, and if
that's the case I cancel the BeforeUpdate. I always use this kind of
code for that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only
way a textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


  #7  
Old February 28th, 2010, 08:41 AM posted to microsoft.public.access
Lars Brownies[_2_]
external usenet poster
 
Posts: 157
Default Check if field is empty (what code to use)

Thanks for your comments.

Lars

"John Spencer" schreef in bericht
...
I tend to use
IF Len([object] & "") = 0 Then
...

Why? a control or a field can can be null or have a value. Text objects
can have a zero-length string value (especially if tied to a field that
allows zero Length strings.

If the object is a number, date, etc then it can be null or have a value,
so you could just test for null.

I don't know if this is still true, but at one time the check for length
was quicker than other tests. It probably makes very little difference in
terms of efficiency given the speed of modern computers. I would think
you would have to be in a loop with hundreds of thousands of iterations to
see any perceived difference as a human.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Lars Brownies wrote:
In a form's BeforeUpdate I check if certain fields are empty, and if
that's the case I cancel the BeforeUpdate. I always use this kind of code
for that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only way
a textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


  #8  
Old March 17th, 2010, 01:33 PM posted to microsoft.public.access
joelgeraldine
external usenet poster
 
Posts: 201
Default Check if field is empty (what code to use)

oomùmµù

"Lars Brownies" a écrit dans le message de groupe de
discussion : ...
Thanks for your comments.

Lars

"John Spencer" schreef in bericht
...
I tend to use
IF Len([object] & "") = 0 Then
...

Why? a control or a field can can be null or have a value. Text objects
can have a zero-length string value (especially if tied to a field that
allows zero Length strings.

If the object is a number, date, etc then it can be null or have a value,
so you could just test for null.

I don't know if this is still true, but at one time the check for length
was quicker than other tests. It probably makes very little difference
in terms of efficiency given the speed of modern computers. I would
think you would have to be in a loop with hundreds of thousands of
iterations to see any perceived difference as a human.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Lars Brownies wrote:
In a form's BeforeUpdate I check if certain fields are empty, and if
that's the case I cancel the BeforeUpdate. I always use this kind of
code for that:

If IsNull([Surname] or Surname = "" then

However, I noticed that others use other ways for checking this:
If Len(Nz([Surname],"")) = 0 Then
If Len(Trim([Surname] & "")) = 0 then
If RTrim([Surname].Text) = Nothing Then
If Nz([SurName],"") = "" Then

I'm wondering what I can use best in this case.

Also I'm wondering, why do you have to check for a "" value? The only
way a textbox could get that value would be through vba, or am I missing
something?

Thanks,

Lars


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.