Full Version: Text box
UtterAccess Forums > Microsoft® Access > Access Forms
EMILYTAN
how to check for the empty text box...
well, i know it is a very simple question
Just to clarify, we cannot put the below code in order to check for empty text box is it?
Me.txt1 = ""
Then, what should I write in order to check for empty text?
Ibrahim
hi
If IsNull(Me.Txt1) Then
MsgBox "Text Box is Null"
Else
MsgBox "Text Box is not Null"
End If
regards,
Ibrahim
Olove Access ... it makes life easier.
thenelson
Better still:
If NZ(MyTextBoxName) = "" Then
Checks for Null and ""
Ibrahim
hi nelson .... good morning...
If NZ(MyTextBoxName) = "" Then
while apply the above, if you have something like "" (2 quotations) in the textbox what will be the result?
it shows null in the textbox !!!!!!!!!
Ibrahim
Olove Access ... it makes life eaiser.
mishej
Microsoft documentation recommends you do this:
CODE
If Len(Me.txt1 & "") = 0 Then
  ' control has no value
End If

hey claim this is the fastest performing way to ensure that you have a value other than Null or an empty string ("").
When you concatenate an empty string ("") to a Null value it "coerces" it to become a String value with no length which can then be measured. If the "txt1" control did have a value then appending an empty string to it would not change its value.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.