A data service rejects a change
Editing a cell or saving a new record in a WklGrid that's bound to a table linked through ODBC
(for example, to a Wkl OData service) fails: the row gets a red bar along its left edge,
DataError is raised, and in VBA, CellValue raises an error such as this one:
The change (Cell value) to the node 1 could not be saved in "tblOData": [Wkl][OData]Der Dienst hat mit 422 geantwortet: Der Vorgang wurde von der Datenbank abgelehnt. (ODBC: Aktualisierung in einer verknüpften Tabelle 'tblOData' fehlgeschlagen.)
Environment
WKL Forms Object Library 1.15 and later; any table linked through ODBC.
Cause
The grid writes through Access (DAO), and Access passes the change to the ODBC driver, which sends it to the service. The service (or the database behind it) rejected the change because of a check constraint, a missing permission (403), or a value the service doesn't accept (422). The message gives the driver's and the service's reason first, followed by the general Access message in parentheses. The change isn't saved, and the values stay in the row.
Resolution
- Read the first part of the message, which is the service's reason. A 422 stating that the database rejected the operation (“von der Datenbank abgelehnt” in the example) points to a database rule (a check constraint, foreign key, or required column); a 403 points to the caller's permissions.
- Correct the value in the row, or press Esc to discard it; in a new row, Esc or Delete discards the record.
- To show the reason in your own message, handle
DataErrorand setResponsetoacDataErrContinue. - To check the rule before the service does, validate the value in the grid's
BeforeUpdate, or set a validation rule on the column (How to: Validate cell input).