Textbox con varias condiciones

Buen día experto me puedes ayudar con el sig problema:
Tengo un texbox1 donde la gente debe ingresar datos, un CommandButton1 para buscar el dato y un textbox2 para mostrar el dato resultante.
Ejemplo :
En el texbox1 ingreso el código "90" o "91", cuando presiono el CommandButton1 me tiene que regresar en el textbox2 la palabra abarrotes y hasta aquí esta bien, pero cuando le doy una nueva búsqueda por ejemplo "92" o "93" y le doy buscar en el CommandButton1 (buscar) me tiene que regresar banorte, y no lo hace me regresa "abarrotes". Y también si ingreso un valor diferente no me muestra el msgbox de información! Me muestra el textbox2 con el texto de de "abarrotes"
El código del CommandButton1 es :
Private Sub CommandButton1_Click()
If TextBox1 = "" Then
MsgBox "Ingrese un dato", vbInformation, "Celda Vacia"
TextBox1.SetFocus
ElseIf Not IsNumeric(TextBox1) Then
Dim mensaje As String
mensaje = MsgBox("Valor ingresado NO es Numerico" & Chr(13) & "Ingrese nuevamente!", vbCritical, Title:="Ingresar Valor Numerico")
TextBox1 = Empty
TextBox1.SetFocus
ElseIf TextBox1 = "90" Or "91" Then
TextBox2.Text = ""
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox2.Text = "abarrotes"
ElseIf TextBox1 = "92" Or "93" Then
TextBox2.Text = ""
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox2.Text = "banorte"
else
msgbox "El dato no existe en la base de datos, revise por favor"
end if
end sub
Espero y tenga solución ya que si es necesario que el usuario ingrese varios datos
Gracias y slds

2 respuestas

Respuesta
1
Ya te respondí esto pero lo dejo por si otros usuarios quieran leerlo:
Las comparaciones se deben realizar repitiendo el nombre del control:
ElseIf TextBox1 = "90" Or TextBox1 = "91" Then
Respuesta
1
Prueba así:
If TextBox1 = "" Then MsgBox "Ingrese un dato", vbInformation, "Celda Vacia": TextBox1.SetFocus
If Not IsNumeric(TextBox1) Then
Dim mensaje As String
mensaje = MsgBox("Valor ingresado NO es Numerico" & Chr(13) & "Ingrese nuevamente!", vbCritical, Title:="Ingresar Valor Numerico")
TextBox1 = Empty
TextBox1.SetFocus
End If
If TextBox1 = "90" Or TextBox1 = "91" Then
TextBox2.Text = ""
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox2.Text = "abarrotes"
ElseIf TextBox1 = "92" Or TextBox1 = "93" Then
TextBox2.Text = ""
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox2.Text = "banorte"
Else
MsgBox "El dato no existe en la base de datos, revise por favor""
End If
No olvide CERRAR la pregunta

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas