by Dinesh Thakur Category: DataBase

When you want to make sure that a required field has an entry or that field has valid data, the Validate event is good location to check. If the field is not valid, you can display an error message and cancel the operation.


New Visual Basic 6, most controls now have a new property and a new event that greatly aid in validating the entries in controls. The Causes Validation property can be set to True or False, which indicates whether validation event occurs for the control just before it loses the focus.


For example, assume you have txtISBN and txtTitle. The user is expected to enter a value in txtISBN and tab to txtTitle. If you have the Causes Validation property of txtTitle set true, then the validate event of txtISBN will occur. Of course, the user may do something else, such as click in a different field, o a command button. You must set the Causes Validation property to true for all controls. Default setting for Causes Validation property is true.


Syntax of Validate Event is:-

Private Sub ControlName_Validate(Cancel As Boolean)

Over here Cancel Argument decides whether focus should be kept or not.


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.