From: David on
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


From: Dirk Goldgar on
"David" <NoWhere(a)earthlink.net> wrote in message
news:e$nfsfYuKHA.2436(a)TK2MSFTNGP04.phx.gbl...
>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.

--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

From: David on
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)
>> If Len(txtName.Text) > 0 Then

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?





"Dirk Goldgar" <dg(a)NOdataSPAMgnostics.com.invalid> wrote in message
news:ONjLyvYuKHA.732(a)TK2MSFTNGP06.phx.gbl...
> "David" <NoWhere(a)earthlink.net> wrote in message
> news:e$nfsfYuKHA.2436(a)TK2MSFTNGP04.phx.gbl...
>>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.
>
> --
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
>
> (please reply to the newsgroup)
>


From: Maurice on
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
--
Maurice Ausum


"David" wrote:

> 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
>
>
> .
>
From: David on
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

"Maurice" <Maurice(a)discussions.microsoft.com> wrote in message
news:4758C1D4-F245-4427-ADD1-8FB46B1299D7(a)microsoft.com...
> 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
> --
> Maurice Ausum
>
>
> "David" wrote:
>
>> 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
>>
>>
>> .
>>