I have a form that checks that the data entered into a textbox is a number and is 9 digits long.
Here is the code I have:
my problem is that if the user enters something that isn't a number or 9 digits long, I want to clear the wrong value and allow the user to enter a new (correct) one - however the cursor still jumps to the next control. Can someone please tell me what I am doing wrong?
ALSO - the "Exit Sub" in the first section is because if the data entered didn't meet condition 1, I can't see any need to report on condition 2. However regarding my having the extra exit location - is this bad form? Should I do a "select Case" instead or does it matter?
Thanks.
Here is the code I have:
Code:
Private Sub txtRoutingNo_Exit(Cancel As Integer) ' be sure routing number is 9 digits and a number
If Not IsNumeric(txtRoutingNo.Value) Then
MsgBox "You must enter Numbers only.", vbInformation, "ACH Database"
txtRoutingNo.Value = ""
Me.txtRoutingNo.SetFocus
Exit Sub
End If
If Not Len(txtRoutingNo.Value) = 9 Then
MsgBox "Routing Number Must be 9 digits.", vbInformation, "ACH Database"
txtRoutingNo.Value = ""
End If
End Sub
my problem is that if the user enters something that isn't a number or 9 digits long, I want to clear the wrong value and allow the user to enter a new (correct) one - however the cursor still jumps to the next control. Can someone please tell me what I am doing wrong?
ALSO - the "Exit Sub" in the first section is because if the data entered didn't meet condition 1, I can't see any need to report on condition 2. However regarding my having the extra exit location - is this bad form? Should I do a "select Case" instead or does it matter?
Thanks.