Re: Error 4140, related records exist. How to find them
Bengt,
First step is to set pbNoCascadeDeleteStrict to true, this enforces you to add DDO's for all child tables
Then add Validate_Cascade_Delete in each child DDO and make it throw an error when a record was found e.g:
Code:
Object oCustomerDataDictionary is a cCustomerDataDictionary
Set pbNoCascadeDeleteStrict to True
Set Cascade_Delete_State to True
End_Object
Object oOrderHeader_DD is a cOrderHeaderDataDictionary
Set DDO_Server to oSalesPerson_DD
Set Constrain_file to Customer.File_number
Set DDO_Server to oCustomerDataDictionary
Function Validate_Cascade_Delete Returns Boolean
Error DFERR_NO_DELETE_RELATED_RECORDS_EXIST "OrderHeader"
Function_Return 1
End_Function
End_Object
Object oOrderDetail_DD is a cOrderDetailDataDictionary
Set DDO_Server to oInventory_DD
Set Constrain_file to OrderHeader.File_number
Set DDO_Server to oOrderHeader_DD
Function Validate_Cascade_Delete Returns Boolean
Error DFERR_NO_DELETE_RELATED_RECORDS_EXIST "OrderDetail"
Function_Return 1
End_Function
End_Object
Now in above situation when you try to delete a customer you will get a DFERR_NO_DELETE_RELATED_RECORDS_EXIST error with the name of the table when orders are found. If you remove the Validate_Cascade_Delete function in the orderheader datadictionary it would allow orders to be deleted that do not have orderdetail lines but as soon as one order is found with detail lines it would bark and revert the delete process.
Regards,
Data Access Worldwide
Vincent Oorsprong