MSG BOX PREVENTS SET FOCUS POST 2

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

Guest

If msg box line is removed from code, text box will be the focus and text
selected. With MSG BOX line left in, its like it just skips the focus and
highlight code

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

End Sub
 
See one alternative at your other post.
If msg box line is removed from code, text box will be the focus and text
selected. With MSG BOX line left in, its like it just skips the focus and
highlight code

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

End Sub
 
Hello helpless in iowa,
I would rather get rid of the message box and use instead a label to get the
attention of the user for example, and I presume that you're using a Userform:
Label2.Visible = True 'alerts the user to enter a numeric value
txtphone.SetFocus
txtphone.SelStart = 0
txtphone.SelLength = 1000
But in the UserForm_Initialize() you have to initialize the Label2.Visible
as False, otherwise it appear when the Userform appears for the first time,
which you won't like.

Swisse
 

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