HELP! Need to check if textbox is empty..

fenerfan

Registered User.
Local time
Yesterday, 20:39
Joined
Dec 3, 2006
Messages
22
Hi There,

I am having trouble with something that should be very simple,

I have a textbox and am trying to check if it is empty:

if text0.text = "" then
.........
end if.

problem is that it doesn't work, tryed a few variations, either returns an error or doesn't return anything at all,

any help would be appreciated.
 
You want to use the .Value property because to use the .Text property requires the control to have the focus. To test for both Null and "" your code will be:
If Len(Me.Text9 & "") = 0 Then
'-- It is empty!
Note: The .Value property is the default property for a control so it is not necessary to spell it out!
Me.Text9
and
Me.Text9.Value
are the same thing.
 
Last edited:
your a legend mate,
cheers
 
@RuralGuy

This worked for me too, such is the power of the forum search! However, could you try to explain to me why this solution works when the following didn't?
  • IsNull(Me.TextBox)
  • IsEmpty(Me.TextBox)
  • Len(Me.TextBox) < 1
  • Me.TextBox = ""
It's infuriating not to know, having tried so many ways! Thank goodness for internet fora.
 
The approach I gave will catch *both* Null fields and ZeroLengthStrings (""). Without knowing the value in your TextBox it is not easy to explain, which is why I try and catch both conditions with the test.
 
Was it this recent thread that you looked at?
http://www.access-programmers.co.uk/forums/showthread.php?t=160263
It offers various takes on the subject.

In theory either
IsNull(Me.TextBox)
or
Me.TextBox = ""
should have yielded the result you'd expect (a character such as a Space would have very likely been removed by the Access UI) - unless you didn't test for them individually or the condition of the textbox altered between tests.
You'd need to give more detail / example.

FWIW the tests
IsEmpty - would fail as Empty is a state which variants are dimensionalised into before being assigned a value (or lack of value such as Null) - it doesn't apply to the state of a control.
Len(Me.TextBox) - would fail for Null (just as would Me.TextBox = "") as the Len function doesn't return a value (other than Null) for a parameter value of Null.
i.e. Len(Null) returns Null. And Null < 1 returns Null. So your expression returns Null - which isn't True or False.

Cheers.
 
Re: Need to check if textbox is empty..

Thank you both. I've no idea why my first two attempts didn't work but @RuralGuy's solution works a treat and that's all I'm really after.
 
How can I do the opposite to IsEmpty - IE if there's something in the text box?

Ruth
 
Hi

As I mentioned previously, IsEmpty isn't a function to determine the state of a Textbox - but variables.
You'd use IsNull and Not IsNull to determine the state of your textbox.

Cheers.
 
Figured it out from another forum while this one was inaccessible, thanks though :)
 

Users who are viewing this thread

Back
Top Bottom