Partager via


How to: Create Validation Rules for Views

You can create local versions of field and record validation rules for views. Creating local validation rules provide the following benefits:

  • Reduce response time.

  • Reduce impact on network resources.

  • Test data before sending it to the remote data source.

  • Prevent sending faulty data to the remote data source.

However, Visual FoxPro does not compare the validation rules that you create locally with the validation rules in the remote data source. Therefore, you must create rules that are appropriate and compliant with the remote data source. If remote data source rules change, the local validation rules must match.

For more information, see Working with Validation Rules.

To create a field or record validation rule for views

  1. Open the view in the View Designer, and click the Fields tab.

  2. In the Selected Fields list, click a field, and click Properties.

  3. In the Rule box from the Field validation area, type the validation expression you want. To build an expression, click the ellipsis (...) button.

  4. To display a custom error message, in the Message box, type the custom error message or expression you want to display for invalid values. To build an expression, click the ellipsis (...) button.

    Note

    Make sure to enclose message text in quotation marks ("").

To create a field or record validation rule for views programmatically

  • Use the DBSETPROP( ) function to set the RuleExpression and RuleText field or record properties for views.

For more information, see DBSETPROP( ) Function.

For example, the following code creates a field-level rule on orditems_view that prevents entering a quantity of less than 1:

OPEN DATABASE testdata
USE VIEW orditems_view
DBSETPROP('Orditems_view.quantity','Field', ;
         'RuleExpression', 'quantity >= 1')
DBSETPROP('Orditems_view.quantity','Field', ;
         'RuleText', ;
'"Quantities must be greater than or equal to 1"')

See Also

Tasks

How to: Edit Views

Other Resources

Managing Views

Working with Views (Visual FoxPro)