Hi
Private Sub Command2_Click()
If Text1.Text = " " And Text2.Text = "" Then
MsgBox "textbox is empty "
End If
End Sub
The above if-else statement doesnt seems to work
Anyone can detect anything wrong with the code?
Printable View
Hi
Private Sub Command2_Click()
If Text1.Text = " " And Text2.Text = "" Then
MsgBox "textbox is empty "
End If
End Sub
The above if-else statement doesnt seems to work
Anyone can detect anything wrong with the code?
Well, there isn't anything wrong, other than:
You have a space at Text1.Text = " "Code:If Text1.Text = " " And Text2.Text = "" Then
Even if you were meant to use the space, it seems to work fine.
Sunny
The code is ok, but it will only fire the MessageBox when both Textboxes are empty, to make the code work if one of (or both) the textboxes are empty replace the AND with OR
Thanks for the reply
I tried a simpler if else statement that goes:
Code:
if text1.text=" " then
msgbox"textbox 1 is empty"
endif
even thought i fufill the condition above no mesage box is display
CoMMIE, " " doesn't mean it is empty, "" means it is empty. " " is the same as pressing the space bar once but thats not the same as nothing. " " still takes space to represent.
Your code should be
SunnyCode:Private Sub Command2_Click()
If Text1.Text = "" And Text2.Text = "" Then 'space deleted
MsgBox "textbox is empty "
End If
End Sub
I'm sorry but what are you trying to do?!
does the text1 exist at all and what's in it when pressing the button? when you delete all the contents in a textbox, the value of the textbox is "", not " " (< space)
Where do you fire the If Then Statement?
I don't get it, what's not working for you?Code:Private Sub Command1_Click()
'Will check if both boxes are empty
If Text1.Text = "" And Text2.Text = "" Then
MsgBox "textbox 1 is empty"
End If
End Sub
Private Sub Command1_Click()
'Will check if one of the boxes are empty
If Text1.Text = "" And Text2.Text = "" Then
MsgBox "textbox 1 is empty"
End If
End Sub
Hi
I already found my solution thanks to Yonatan
Anyway thanks for spending time reading my post :)Code:Private Sub Command1_Click()
If Trim(Text1.Text) = vbNullString Then
MsgBox " "
Else
End If