Home > Enterprise >  VBA Check If Textbox Is Null then send message
VBA Check If Textbox Is Null then send message

Time:10-23

first end second if statments working (combobox and textbox <10 ) but third is not(null value). Why?

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex = -1 Then
MsgBox "bla"
Exit Sub
End If
If CDbl(TextBox1.Text) < 10 Then
    MsgBox "bla!"
Exit Sub
End If
If (TextBox1.Value = Null) Then
    MsgBox "bla!"
End If
Exit Sub

CodePudding user response:

I think there is logical error when ı try to reverse if condition between null and smaller its worked. Here is the correct form;

Private Sub CommandButton1_Click()
If ComboBox1.ListIndex = -1 Then
MsgBox "bla"
Exit Sub
End If
End If
If TextBox1.Text= "" Then
    MsgBox "bla!"
End If
Exit Sub
If CDbl(TextBox1.Text) < 10 Then
    MsgBox "bla!"
Exit Sub

CodePudding user response:

You can't compare with Null. Use IsNull:

Private Sub CommandButton1_Click()

    If ComboBox1.ListIndex = -1 Then
       MsgBox "bla"
       Exit Sub
    End If
    If CDbl(TextBox1.Text) < 10 Then
       MsgBox "bla!"
    Exit Sub
    End If
    If IsNull(TextBox1.Value) Then
       MsgBox "bla!"
    End If

Exit Sub
  • Related