Monday 11 April 2011

Perform validation on blank fields in a VBA form

When a user is inputting information it will be necessary to build in some quality checks to prevent the user from entering inaccurate or poorly formatted information. VBA_logo
One type of validation check that should be carried out involves checking to see if any important/mandatory fields have been left blank. The code below will check this and prompt the user if the information has not been provided.
If productID.Text = "" Then MsgBox ("Please enter the product ID")
If productID.Text = "" Then Exit Sub

This code pops up a message to the user to enter the product ID and when they click ‘OK’ the second line ensures the field is blank ready for user input.
This code should be added to your ‘Submit’ button.



No comments:

Post a Comment