Extend Microsoft Access Applications to the Cloud: Creating a Blank Web App and Using Templates
Adding validation rules
A web app has validation features similar to a desktop database, but it uses a different set of functions to support validation. Each table is allowed a validation rule and message. The table-level validation rule is used to cross-validate data and compare the values in several fields. Depending on the data type, each field can have a separate validation rule, which normally refers only to the field but can make references to the values in other fields. (This is a feature that is not available in desktop database field validation rules.)
In the sample web app in this chapter, look at the template table Customers and click the Validation Rule button on the Design contextual ribbon tab. You will see the rule displayed in the Expression Builder dialog box, as shown in Figure 4-15.
FIGURE 4-15 Expression Builder dialog displaying a validation rule.
The preceding example of a table-level validation rule ensures that one of the four specified fields has to contain a value:
- Coalesce([First Name],[Last Name],[Email],[Company]) Is Not Null
Individual fields can also have a single validation rule. For example, in the Products table, if you want to ensure that each product code starts with the string “01-“, you could add the validation rule shown in Figure 4-16.
FIGURE 4-16 Field validation rule and text.
In this example, you find the rule Left([Product Code],3) = "01-", which checks that each product code starts with “01-“. When entering the rule, you can choose to use single quotes (such as ‘01-’), which would also be accepted.