ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MSG BOX PREVENTS SET FOCUS POST 2 (https://www.excelbanter.com/excel-programming/321019-msg-box-prevents-set-focus-post-2-a.html)

helpless in iowa[_2_]

MSG BOX PREVENTS SET FOCUS POST 2
 
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

Dave Peterson[_5_]

MSG BOX PREVENTS SET FOCUS POST 2
 
See one alternative at your other post.

helpless in iowa wrote:

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


--

Dave Peterson

swisse

MSG BOX PREVENTS SET FOCUS POST 2
 
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



All times are GMT +1. The time now is 06:49 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com