Please consider a grid with 2 columns (simplified). The first column is a 'lookup' column ("Name") while the second is a required field (ID Number).
Column A is used to select a 'Name' from a DB Lookup list and fill the associated ID Number into the second Column: "ID Number". Note that the actual value for "Name" does not have an underlying Field component in this table - column A just exists to get the ID Number and enter it in the table.
If one tries to post a record without selecting the 'Name' (and hence adding the ID number into the ID number field), one gets the error message "Field "ID Number" must have a value".
This could, of course, be confusing to the end user as the field they're entering is "Name" - not "ID Number" (especially if the ID number is not visible in the grid) ....
How can one intercept the database error mechanism to change the error message to "Field "Name" must have a value" to avoid confusion when the ID Number Field is null?
Intercept/change DB error message
Re: Intercept/change DB error message
You can try processing the BeforePost event for TDataSet and check the value of the field you're interested in. If the value is invalid, you can generate a custom error for the user. For example:
Code: Select all
procedure TForm1.UniQuery1BeforePost(DataSet: TDataSet);
begin
if DataSet.FieldByName('Field_Name').IsNull then
DatabaseError('Error message');
end;
Re: Intercept/change DB error message
Thanks Stellar,
That's what I have now started doing and it works fine.
I was thinking there might be a simpler way.
That's what I have now started doing and it works fine.
I was thinking there might be a simpler way.
Re: Intercept/change DB error message
Glad to see that the issue was resolved.
Feel free to contact us if you have any further questions about our products.
Feel free to contact us if you have any further questions about our products.