Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setfocus isn't working?

Status
Not open for further replies.

4281967

MIS
Oct 14, 2005
74
US
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:
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.
 
How are ya 4281967 . . .

In VBE help, have a look at the [blue]Undo[/blue] property.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top