View Single Post
  #6 (permalink)  
Old February 19th, 2008, 02:26 PM
BrianWren BrianWren is offline
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When validation fails, set the focus to the textbox, and exit the validating sub.
You can post a MessageBox first to alert the user as to why you are sending them back to the box.

It is not a very friendly thing to do to delete the contents when the contents are wrong, but of course you could. If that triggers a _Change event, and that's a problem, do this. Create a global boolean. At the top of the _Change event routine add If MyBoolean = True Then Exit Sub. In the validation routine, before deleting the contents, set MyBoolean to True. Empty the contents, then set the Boolean back to false.

You can sent the focus back to the cantrol, set the controls SelectionStart to 0 or 1 (I fergit), and set the SelectionLength to Textbox.Text.Length(). (The actual terms might be a little differetn, but this should at least convey the idea...)