WklValidator
WklValidator checks the fields of the Access form it's placed on (a list's edit form, a dialog
box, or any bound form) against rules per field and per record. It shows errors next to the fields
and in a summary, and it prevents a record that breaks a rule from being saved, all without message
boxes.
Get started
Common tasks
- How to: Validate cell input: the same rules as columns of
WklGrid
Visual aid
+- frmCustomer: Form View ---------------------------------------------+ | Name [ Miller ] | | ZIP [ 123 ] <- red border, tooltip: message | 1 | Email [ ] | | | | (x) 2 errors – The ZIP code has five digits. | 2 +----------------------------------------------------------------------+
| Region | Meaning |
|---|---|
| 1 | A field that breaks a rule: red border and the message as a tooltip; the focus stays in the field |
| 2 | The validator: the summary with the number of errors and the first message; clicking it goes to the first error |
Key features
- Rules per field: required, length, regular expression, range, value list, and a custom message; each rule can apply only while another field has certain values (
when). - Rules per record: exactly one, at least one, or at most one of several fields.
- Rules in a designer or as JSON (
Rules), saved with the form. - Behaves the way Access does: a broken rule keeps the focus in the field, and a record that breaks a rule isn't saved, even when the focus moves from a docked edit form back to its list.
- Data source errors on save (a table's validation rule, a data service rejecting the record) appear in the summary instead of in an Access message box (
HandleDataErrors). - Code:
Validate,SetErrorfor errors your own code detects,ErrorCount,GoToFirstError, and theValidateRecordevent. - Screen readers announce new errors in the summary without moving the focus out of the field.
Core concepts
It listens to Access events. The validator connects to the events of the form and of its text boxes and combo boxes. Access passes a form's events to a control only when the form has a module, so Has Module must be Yes; an empty module is enough. The validator sets the event properties it needs to [Event Procedure] on its own.
One validator per form. It checks the controls on its own form; a subform needs its own validator. In Design view, the validator shows its name and the number of rules.
Not a replacement for table rules. Table and server rules still apply; the validator shows their rejections in the same summary.
Administration
Troubleshooting
For developers
Related topics
None