ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   MSG BOX PREVENTS setfocus HELP (https://www.excelbanter.com/excel-programming/321011-msg-box-prevents-setfocus-help.html)

helpless in iowa

MSG BOX PREVENTS setfocus HELP
 
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

swisse

MSG BOX PREVENTS setfocus HELP
 
Remove the command Exit Sub.

Swisse

helpless in iowa[_2_]

MSG BOX PREVENTS setfocus HELP
 
i have removed that it still dosent work


"swisse" wrote:

Remove the command Exit Sub.

Swisse


Dave Peterson[_5_]

MSG BOX PREVENTS setfocus HELP
 
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

helpless in iowa wrote:

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


--

Dave Peterson

helpless in iowa[_2_]

MSG BOX PREVENTS setfocus HELP
 
Thanks, but this does not fix the problem. I still need to set the focus back
to the textbox

"Dave Peterson" wrote:

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

helpless in iowa wrote:

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


--

Dave Peterson


swisse

MSG BOX PREVENTS setfocus HELP
 
Read my answer at your other post.

Swisse

Tom Ogilvy

MSG BOX PREVENTS setfocus HELP
 
Cancel = True
causes the focus not to leave the textbox.

--
Regards,
Tom Ogilvy

"helpless in iowa" wrote in
message ...
Thanks, but this does not fix the problem. I still need to set the focus

back
to the textbox

"Dave Peterson" wrote:

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

helpless in iowa wrote:

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


--

Dave Peterson





All times are GMT +1. The time now is 02:45 AM.

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