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  

Adding/Editing Empty String Fields



 
 
Thread Tools Display Modes
  #1  
Old March 1st, 2010, 09:41 PM posted to microsoft.public.access
David[_62_]
external usenet poster
 
Posts: 13
Default Adding/Editing Empty String Fields

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


  #2  
Old March 1st, 2010, 10:09 PM posted to microsoft.public.access
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Adding/Editing Empty String Fields

"David" wrote in message
...
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)

  #3  
Old March 1st, 2010, 10:23 PM posted to microsoft.public.access
David[_62_]
external usenet poster
 
Posts: 13
Default Adding/Editing Empty String Fields

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" wrote in message
...
"David" wrote in message
...
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)



  #4  
Old March 1st, 2010, 10:29 PM posted to microsoft.public.access
Maurice
external usenet poster
 
Posts: 1,585
Default Adding/Editing Empty String Fields

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


.

  #5  
Old March 1st, 2010, 11:18 PM posted to microsoft.public.access
David[_62_]
external usenet poster
 
Posts: 13
Default Adding/Editing Empty String Fields

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" wrote in message
...
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


.



  #6  
Old March 2nd, 2010, 12:09 AM posted to microsoft.public.access
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Adding/Editing Empty String Fields

"David" wrote in message
...
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.


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.

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

(please reply to the newsgroup)

  #7  
Old March 13th, 2010, 05:55 PM posted to microsoft.public.access
De Jager
external usenet poster
 
Posts: 393
Default Adding/Editing Empty String Fields


"David" wrote in message
...
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


  #8  
Old March 17th, 2010, 01:11 PM posted to microsoft.public.access
joelgeraldine
external usenet poster
 
Posts: 201
Default Adding/Editing Empty String Fields

immùm

"David" a écrit dans le message de groupe de
discussion : ...
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

 




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 08:41 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.