how to test blank text boxes

raychoy2k

Registered User.
Local time
Yesterday, 22:04
Joined
Feb 24, 2003
Messages
29
Kind dumb question but, how do I test for empty text boxes in VBA?

I am using the following code to do this, but it does not work. Should I be testing for empty string ("") or NULL? I tried both and it doesnt work.

If Me![Phone] = Null And Me![name] = Null Then
 
If IsNull(Me![Phone]) And IsNull(Me![name]) Then

HTH
RDH
 
You might want to also test for an empty string just in case the user deletes the value from the text box for that type of instance would no longer be Null.

If IsNull(tbPhone) Or tbPhone = "" And IsNull(tbName) Or tbName = "" Then

You should be careful with using reserved function names. "Name" is a reserved word and you should be careful not to use it as the name of a field or object.

HTH
 
Just a suggestion if you want to chk for null and and "" at the same time use,

If nz(tbPhone,"") = "" And nz(tbName,"")= "" Then




:cool:ShadeZ:cool:
 
I hate to be picky but when you use AND and OR operators in the same conditional, you almost always need to use parentheses to control the order of evaluation.

If (IsNull(tbPhone) Or tbPhone = "") And (IsNull(tbName) Or tbName = "") Then

Without parens, AND takes presidence over OR and so the statement will be evaluated as:

If IsNull(tbPhone) Or (tbPhone = "" And IsNull(tbName)) Or tbName = "" Then

Which is TOTALLY wrong.
 
Thanks guys. I later discovered that IsNull is the one I wanted. My problem is not knowing what to do, it is knowing what is available in Access and learning the new syntax.

All suggestions were a lot of help though. Thanks!
 
Pat Hartman said:
I hate to be picky but...
But Pat, that's why we love you!:D

RayChoy, you may find this article useful in differentiating nulls, zero values, and zero-length strings.

--Prefers-Picky Mac
 
Last edited:

Users who are viewing this thread

Back
Top Bottom