ValidationRule Property

See Also        Applies To

Sets or returns a value that validates the data in a field as it's changed or added to a table (Microsoft Jet workspaces only).

Syntax

VOIDSetValidationRule(LPCTSTR pstr );

CStringGetValidationRule(VOID);

Parameters

Type Example Description
LPCTSTR pstr A pointer to string that contains a comparison in the form of an SQL WHERE clause without the WHERE reserved word.

Remarks

For an object not yet appended to the Fields collection, this property is read/write.

The ValidationRule property determines whether or not a field contains valid data. If the data is not valid, a trappable run-time error occurs. The returned error message is the text of the ValidationText property, if specified, or the text of the expression specified by ValidationRule.

For a CdbField object, use of the ValidationRule property depends on the object that contains the Fields collection to which the CdbField object is appended.

Object appended to Usage
CdbIndex Not supported
CdbQueryDef Read-only
CdbRecordset Read-only
CdbRelation Not supported
CdbTableDef Read/write

For a CdbRecordset object, use of the ValidationRule property is read-only. For a CdbTableDef object, use of the ValidationRule property depends on the status of the CdbTableDef object, as the following table shows.

TableDef Usage
Base table Read/write
Linked table Read-only

Validation is supported only for databases that use the Microsoft Jet database engine.

The string expression specified by the ValidationRule property of a CdbField object can refer only to that CdbField. The expression can't refer to user-defined functions, SQL aggregate functions, or queries. To set a CdbField object's ValidationRule property when its ValidateOnSet property setting is True, the expression must successfully parse (with the field name as an implied operand) and evaluate to True. If its ValidateOnSet property setting is False, the ValidationRule property setting is ignored.

The ValidationRule property of a Recordset or TableDef object can refer to multiple fields in that object. The restrictions noted earlier in this topic for the CdbField object apply.

For a table-type CdbRecordset object, the ValidationRule property inherits the ValidationRule property setting of the CdbTableDef object that you use to create the table-type CdbRecordset object.

For a CdbTableDef object based on an linked table, the ValidationRule property inherits the ValidationRule property setting of the underlying base table. If the underlying base table doesn't support validation, the value of this property is a zero-length string ("").

Note If you set the property to a string concatenated with a non-integer value, and the system parameters specify a non-U.S. decimal character such as a comma (for example, strRule = "PRICE > " & lngPrice, and lngPrice = 125,50), an error will result when your code attempts to validate any data. This is because during concatenation, the number will be converted to a string using your system's default decimal character, and Microsoft Jet SQL only accepts U.S. decimal characters.