INTRODUCTION TO DATABASE USING MICROSOFT ACCESS 2013 Part 5.2 November 16, 2014
TYPES OF VALIDATION RULE
FIELD VALIDATION RULE Use a field validation rule to check the value that you enter in a field when you leave the field. For example, suppose you have a Date field, and you enter >=#01/01/2007# in the Validation Rule property of that field. Your rule now requires users to enter dates on or after January 1, If you enter a date earlier than 2007 and then try to place the focus on another field, Access prevents you from leaving the current field until you fix the problem.
RECORD VALIDATION RULE Use a record validation rule to control when you can save a record (a row in a table). Unlike field validation rules, record validation rules refer to other fields in the same table. You create record validation rules when you need to check the values in one field against the values in another. For example, suppose your business requires you to ship products within 30 days and, if you don't ship within that time, you must refund part of the purchase price to your customer. You can define a record validation rule such as [RequiredDate]<=[OrderDate]+30 to ensure that someone doesn't enter a ship date (the value in the RequiredDate field) too far into the future.
WHERE YOU CAN USE VALIDATION RULES You can define validation rules for tables and for controls on forms. When you define rules for tables, those rules apply when you import data. To add validation rules to a table, you open the table in Design view and set various table properties. To add validation rules to a form, you open the form in Design view and add rules to the properties of individual controls.
WHAT YOU CAN PUT IN A VALIDATION RULE Your validation rules can contain expressions — functions that return a single value. You can use expressions to perform calculations, manipulate characters, or test data. When you create validation rules, you use expressions primarily to test data. For example, an expression can check for one of a series of values, such as "Tokyo" Or "Moscow" Or "Paris" Or "Helsinki". Expressions can also perform mathematical operations. For example, the expression <100 forces users to enter values less than 100. The expression ([OrderDate] - [ShipDate]) calculates the number of days that elapsed between the time an order was placed and the time it shipped.
CREATING A VALIDATION RULE
BEGIN Click MS Access 2013 On the MS Access Screen Pane, select Blank Database Create a name that will reserve as your file for the database
In the screen pane, click blank desktop database
In the screen box, click the browse button to save in any file that you want Write your name in the box that you want to save your database Click create if done
IN THE MS ACCESS ENVIRONMENT Right Click the “Table 1”.
Click Design View
Save first. Write your name inside the Table Name Box Click “OK” if done.
You are now in the Design View.
HOW TO ADD FIELDS IN THE DESIGN VIEW Write first your Field Name.
Second, select from the data type that you want.
Third, is to write a short description based on your field name.
If you're done. Click the General Properties (Field) to emphasize your field.
CREATING A VALIDATION RULE In the validation rule, follow the format that was given in Part 5.1
For example You can get input mask as much as possible if you want.
CREATING A VALIDATION RULE IN A DIFFERENT WAY Click the button with …
The button has been entered and you can write some functions. After you write expressions in the Expression Builder, click OK.
After your done, creating the validation rule. You need to write first your validation text before you save. Like this.
PUTTING IT IN THE DATABASE VIEW Right Click Table1. Click Datasheet View. Don’t forget to save your design view
YOU ARE NOW IN THE DATASHEET VIEW
You can get more records when you are in the datasheet view. A sample will be like this.
WHAT IF THE REQUIRED FIELD CAN’T BE
The message is So you need to be sensitive in writing your field. Check your Design View if it follows the format for the validation rule.
Then it backs
If you want to change your Validation Rule. As long as it follows the format in there.
VALIDATE DATA DURING ENTRY IN FORMS The easiest and fastest way to apply a validation rule to a form is to first add the rule to the underlying table field, and then use the automated form-creation tools that Access provides to create a form. For example, on the Create tab, in the Forms group, you can choose to have Access create a simple form, a split form, a multiple- item form, and more. When you use one of those tools, the controls on the form inherit the underlying table properties, including any validation rules and validation text. You can also apply a validation rule to a form control by opening the form in Design view and adding a rule to the Validation Rule property and message text to the Validation Text property of the control. You can add validation rules to some, but not all, form controls. The easiest way to determine if you can add a validation rule to a control is to open the form in Design view and follow the steps in this section.
Remember that a control can have a different validation rule than the table field to which the control is bound. When a conflict develops between validation rules, the rule defined for the table field takes precedence. Also, remember that rules in controls and table fields can cancel each other out and thus prevent you from entering any data at all. For example, suppose you apply the following rule to a date field in a table: <#01/01/2007# But you then apply this rule to the form control bound to the table field: >=#01/01/2007# The table field now requires values earlier than the year 2007, but the form control forces you to enter dates after that year, thus preventing you from entering any data at all. If you try to enter data under those conditions, Access tells you to enter dates before and after those specified by the conflicting validation rules, and you find yourself caught in an endless loop. The following steps explain how to add validation rules to controls, and how to lock controls and thus prevent users from altering data.