Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Text Box For Null Value 1

Status
Not open for further replies.

Kevsim

Instructor
Apr 18, 2000
385
AU
I wish to check a text box for any data, if empty or null value a message will be displayed.
I am using the following code but it does not display any message, empty or not.

If IsNull(Me!Text8) Then
MsgBox "No Record To Edit"
Exit Sub
Else
End If

I would appreciate any advise.
kevsim
 
what event is the code applied to?

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work
 



How about...
Code:
If Me!Text8.Text = "" Then
  MsgBox "No Record To Edit"
  Exit Sub
End If


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
how about
if trim(me.text8 & " ") = ""
This covers three cases
Null
empty string ""
or 1 or more spaces
 
Skip,
The "Text" property is not valid unless the text box has the focus.

I typically use and recomment MajP's solution. I would add a suggestion to change "Text8" to a name that makes sense when you are reviewing the code.


Duane
Hook'D on Access
MS Access MVP
 
I thank you all for the input.
I tracked the fault a little further where a new record showed "Null" when the code was ran for the Text8 box and the lowest record showed "" for the text8 box. The text for the box was set for Allow Zero Length in the table, I have now changed this to No.
I used the solution provided by MajP.
One point, after Me is a full stop, the code shows an error, it should be an exclamation mark.
kevsim
 
it should be an exclamation mark

No, not really. Either is fine. When you add a control to a form it makes it a property of the form and it also adds it as an item in the form's "controls" collection.

To refer to any property of an object you use
object.nameofproperty
so
Me.text8.value
is correct. Since 'value' is the default property of a control you can drop the 'value" and just do Me.text8

You can also use the form's controls collection. You reference a collections index using an exclamation. Such as
Object.collectionName!itemindex

Me.Controls!text8.value
However value is the default property of a control and controls is the default property of the form. So you can drop one or all of them. This gives you
Me!Text8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top