Note. Check if the TextBox1
is empty is easy by using TextBox1.Value = ""
.
But the problem is when the user hit the spacebar
, TextBox1
will still recognize it as a value. In such case, my data will appear as an empty cell with 1 space
inside. So my question is, is there any method to check TextBox1.value
for empty and also not consist of space
whether there are 1 or more space
? Million thanks to all.
Here is the code to check whether value is present or not.
If Trim(textbox1.text) <> "" Then
'Your code goes here
Else
'Nothing
End If
I think this will help.
Most terse version I can think of
Len(Trim(TextBox1.Value)) = 0
If you need to do this multiple times, wrap it in a function
Public Function HasContent(text_box as Object) as Boolean
HasContent = (Len(Trim(text_box.Value)) > 0)
End Function
Usage
If HasContent(TextBox1) Then
' ...
You can use the following code to check if a textbox object is null/empty
'Checks if the box is null
If Me.TextBox & "" <> "" Then
'Enter Code here...
End if
Source: Stackoverflow.com