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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS