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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|