Ver Mensaje Individual
  #6 (permalink)  
Antiguo 28/07/2011, 20:35
JonathanB
Usuario no validado
 
Fecha de Ingreso: junio-2010
Ubicación: Guatemala
Mensajes: 196
Antigüedad: 13 años, 10 meses
Puntos: 25
Mensaje Respuesta: Como hacer para validar un textbox?

Saludos, lo que sucede es que después de ejecutar el msgbox, se esta pasando foco al siguiente control (ciclo infinito).

Para solventar tu problema del ciclo infinito, te recomiendo devolverle el foco al control antes de mostrar el msgbox.

Código vb:
Ver original
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2.     If KeyAscii = 13 Then SendKeys "{TAB}"
  3. End Sub
  4.  
  5. Private Sub Text1_LostFocus()
  6.     If Trim(Text1.Text) = Empty Then
  7.         Text1.SetFocus
  8.         MsgBox "No puede estar en blanco!", vbInformation
  9.     End If
  10. End Sub
  11. Private Sub Text2_KeyPress(KeyAscii As Integer)
  12.     If KeyAscii = 13 Then SendKeys "{TAB}"
  13. End Sub
  14.  
  15. Private Sub Text2_LostFocus()
  16.     If Trim(Text2.Text) = Empty Then
  17.         Text2.SetFocus
  18.         MsgBox "No puede estar en blanco!", vbInformation
  19.     End If
  20. End Sub

Espero que te haya sido de utilidad