Detecting Zero-Length String or NULL of Text Control.

G

Guest

How do I detect when a text control is blank when the form is Newly opened
and after updates?

I have a form that has fields that must be filled in. The controls are
checked by a procedure that checks IsNull for each control. The IsNull
procedure is called when a specific combo box is updated (the text controls
must have values before the combo box event is called).

The first time I open the form the IsNull checking procedure works Ok but
then once I update the record, then clear a single text control (to test it),
and then update the combo box again, the IsNull procedure no longer detects
that the text control is blank. Any ideas?

Maybe I need to check for zero length string AND IsNull for each control?
 
S

Stefan Hoffmann

hi Mac,
How do I detect when a text control is blank when the form is Newly opened
and after updates?

If Len(Trim(Nz(Ctl.Value, ""))) > 0 Then _
MsgBox "Not blank."


mfG
--> stefan <--
 
A

Allen Browne

A control with no value in it is Null. It will not be a zero-length string
unless a ZLS is explicitly assigned to it or entered there.

Typical assignments include:
a) Code like this:
Me.Text1 = ""
b) Setting a Default Value of:
""

If the control is bound to a Text field, you can prevent the possibility of
a ZLS by opening the table in design view, selecting the field, and settings
its Allow Zero Length property to No in the lower pane of table design. This
saves having to test for both cases.

For code that sets Allow Zero Length to No for all fields in your database,
see:
Problem properties
at:
http://allenbrowne.com/bug-09.html

If you wish to check for null or a zls, the code would be:
If IsNull(Me.text1) or Me.text1 = vbNullString
(That's probably the most readable, though there are lots of other ways to
write the line.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top