Empty TextBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top