Adding/Editing Empty String Fields

  • Thread starter Thread starter David
  • Start date Start date
D

David

I have a number of textboxes which may or may Not be Empty.
I don't use Resume Next

Is there anyway besides screening each field such as:

If Len(txtName.txt) > 0 Then
!fldName = txtName.txt
End If

to keep the ".Edit" or ".Add" from generating an error if the textbox
is Empty.

Thanks
David
 
David said:
I have a number of textboxes which may or may Not be Empty.
I don't use Resume Next

Is there anyway besides screening each field such as:

If Len(txtName.txt) > 0 Then
!fldName = txtName.txt
End If

to keep the ".Edit" or ".Add" from generating an error if the textbox
is Empty.


I think you must be talking about checking the .Text property, not .txt.
But you don't have to check the .Text property, which requires that the text
box have the focus. In principle, you can check each text box like this:

If Len(txtYourTextbox & vbNullString) > 0 Then
!fldName = txtYourTextbox
End If

Do I gather correctly that you are taking values from these text boxes and
using them to update a recordset? Knowing exactly what you are doing would
help in advising you.

The above code, you should be aware, will not modify an existing value in
!fldname if the text box is empty. Is that what you intended? You might
want the field value to be set to Null. If that's the case, you would have
to do something like this:

If Len(txtYourTextbox & vbNullString) > 0 Then
!fldName = txtYourTextbox
Else
!fldName = Null
End If

However, if you are dealing with required fields, you're going to get an
error if you try to save a record with a required field set to Null. More
information would be helpful.
 
Mr. Goldgar thanks for responding.

My typepo, s/b .Text not .txt

and Yes, I am looking to screen Empty textboxes prior to Adding or Editing
in an Access DB.

Not sure what you gain by using "& vbNullString" ??
I believe either

mine (with correction)
or yours
If Len(txtYourTextbox & vbNullString) > 0 Then

will work.

Was hoping there might be a better way (e.g. some default you could set on
the Access field) for example?
 
You can also test by using: if isnull(me.text) then... but that's just for
each control. I assume you want to check the various textboxes.

This might give you a start see if you can tune it up to your own wishes:
'-----
Dim ctl As Control

For Each ctl In Me
If TypeOf ctl Is TextBox Then
If IsNull(Me.Text) or me.text="" Then
'do something here
End If
End If
Next
'-------------

hth
 
Thanks for response Maurice.

Familiar with "For Each". Won't work for what I want this App.
Had hoped for a simpler way but I guess Len(whatever) is probably as easy as
any.

Thanks
David
 
David said:
Mr. Goldgar thanks for responding.

My typepo, s/b .Text not .txt

and Yes, I am looking to screen Empty textboxes prior to Adding or Editing
in an Access DB.

Not sure what you gain by using "& vbNullString" ??
I believe either

mine (with correction)

or yours


will work.

They are not the same. In Access, unlike VB, the .Text property is only for
special use, and can only be read when the control has the focus. The Value
property (which is the default property of a text box) can be accessed at
any time, no matter where the focus is.
Was hoping there might be a better way (e.g. some default you could set on
the Access field) for example?

It isn't clear to me what you want to do, so I can't suggest a better way.
If you'd like to explain in more detail what you have and are attempting to
accomplish, maybe I can give you better help.
 
David said:
I have a number of textboxes which may or may Not be Empty.
I don't use Resume Next

Is there anyway besides screening each field such as:

If Len(txtName.txt) > 0 Then
!fldName = txtName.txt
End If

to keep the ".Edit" or ".Add" from generating an error if the textbox
is Empty.

Thanks
David
 
Back
Top