Empty TextBox

I

Igor G.

Why this code can't response empty textbox?
I also try with ""
Thanks!

Private Sub Command1_Click()
If [Text10] = Empty Then
MsgBox "Please enter value!", vbExclamation, "ERROR"
Else
DoCmd.OpenForm "My Form"
End If
End Sub
 
D

Dirk Goldgar

Igor G. said:
Why this code can't response empty textbox?
I also try with ""
Thanks!

Private Sub Command1_Click()
If [Text10] = Empty Then
MsgBox "Please enter value!", vbExclamation, "ERROR"
Else
DoCmd.OpenForm "My Form"
End If
End Sub

The "Empty" keyword isn't suitable for what you are trying to do.
Probably the text box is Null, but you can't check for "= Null", because
nothing is ever equal to Null. Instead, use the IsNull() function:

If IsNull([Text10]) Then

If it's possible that the text box might contain a zero-length string
("") instead of Null, you can test for both possibilities at once with
the following statement:

If Len([Text10] & "") = 0 Then
 
Top