Condicionar valor de textbox y mandar mensaje de error

Experto,
Quisiera saber la forma en que puedo condicionar una textbox, de que en caso de que no contenga ningún valor mande un mensaje de error y regrese al textbox para escribir valor.
Tengo el siguiente código, pero en lugar de que se cumpla la condición me descarga el formulario y no me da la opción de regresar a el.
Private Sub CommandButton1_Click()
ifila = ActiveCell.Select
ActiveCell.Value = Form1.TextBox1.Text
If TextBox1.Value = "" Then
MsgBox "No se ha ingresado Nueva Segmentacion", vbInformation
Else
ifila = ActiveCell.Select
ActiveCell.Value = Form1.TextBox1.Text
End If
Me.TextBox1.Value = ""
Unload Me
End Sub

1 Respuesta

Respuesta
1
Prueba con esto:
Private Sub CommandButton1_Click()
ifila = ActiveCell.Select
ActiveCell.Value = Form1.TextBox1.Text
If Trim(TextBox1) = Empty Then
MsgBox "No se ha ingresado Nueva Segmentacion", vbInformation
TextBox1.SetFocus: Exit Sub
Else
ifila = ActiveCell.Select
ActiveCell.Value = Form1.TextBox1.Text
End If
Me.TextBox1.Value = ""
Unload Me
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas