View Full Version : Solved: keep cursor in textbox...
av8tordude
05-14-2010, 05:35 AM
I have a userform textbox that requires a minimum of 4 characters. I'm able to trigger a msgbox when exiting the textbox if the textbox has less than 4 characters, but I would like the cursor to remain in the textbox with the characters highlighted. Can someone provide assistance.
Thanks
YasserKhalil
05-14-2010, 05:42 AM
Try this
TextBox1.SetFocus
Excel Lover
Bob Phillips
05-14-2010, 05:44 AM
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not DataOK Then
MsgBox "oops!"
With Me.TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
Cancel = True
End With
End If
End Sub
av8tordude
05-14-2010, 06:04 AM
Thank you both. Works great:beerchug:
av8tordude
05-14-2010, 06:17 AM
One other thing, when I close the userform, the msgbox appears. How do I do prevent the msgbox from appearing when I close the userform.
av8tordude
05-14-2010, 07:11 AM
Can anyone help. Thanks
mdmackillop
05-15-2010, 12:56 AM
Try the _BeforeUpdate event instead of _Exit
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.