MSG BOX PREVENTS setfocus HELP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If a letter is enterd into the text box, it sends a msg box to say must be
numeric and then should set focus and highlight last enterd text to change
it. If I remove the msgbox it selects the text box and highlites if the msg
box line is left in it does not select the textbox and does not hightlite
what am i doint wrong thanks in advance:

Private Sub txtphone_Change()
If Not IsNumeric(txtphone) Then
MsgBox "Must be Numeric"
txtphone.SetFocus
txtphone.SelStart = 0
txtphone.SelLength = 1000
Exit Sub
End If

End Sub
 
Maybe you could just validate the textbox when the user tries to leave:

Option Explicit
Private Sub txtphone_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(txtphone.value) Then
MsgBox "Must be Numeric"
Cancel = True
End If
End Sub
 
Thanks, but this does not fix the problem. I still need to set the focus back
to the textbox
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top