Validating Text Boxes and Focus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Row

    Validating Text Boxes and Focus

    I have to do a program that involves validating four text boxes that, when entered, are only supposed to be an integer. If anything but an integer is entered, the focus should not move onto the next text box. This whole procedure has do be done in a single event handler.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    Code:
    Private Sub Text1_LostFocus()
    ...
    ...
       If Not IsNumeric(Text1) Then GoTo Error_String
       If Val(Text1) - Fix(Val(Text1)) <> 0 Then GoTo Error_Integer
    ...
    ...
    Exit Sub
    Error_String:
       MsgBox "enter number"
       Text1.SetFocus
    Exit Sub
    Error_Integer:
       MsgBox "enter integer"
       Text1.SetFocus
    End Sub

    Comment

    Working...