Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996

Validating Input Data in LostFocus

Question:
I have two fields on the screen that I use to enter a date range. I want to check the entry on the lost focus with IsDate, and in the event that IsDate = False, inform the user, set the Focus back on the field, and ExitSub before I continue. Since the ending date field follows in the tab sequence, the resulting behavior is that it shows a message box from each control that that date does not work. To the user it just looks as if ithe same message box comes up twice. Any suggesstions, and will VB 4.0 work better.

Answer:
There's an inherent problem in what you are doing. LostFocus is a good place to do validation, as you've already seen. Unfortunately, you can't set focus back to the box for the following reason: let's say that the user pressed something into the box, got an error, and wants to cancel. The user will get a second error when the lostfocus event happens again when he/she goes to click the Cancel button. But since the lostfocus event will put focus back to the box, the user won't be able to exit. You should probably set a variable if the validation fails, and check the value before committing the data.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date