[SOLVED] Deleting Records with detail forms Error

good afternoon guys. im having this error when deleting records from my master form.

the error is “Database Error: The record was not deleted”. can anyone tell me what causes this error and how to fix it. thank u so much.

take note that i have 2 detail forms… thanks again. :slight_smile:

If this is a database error and not a php error then it’s most logical that you have a referential integrity issue. You try to delete a parent record while there are childs left. Databases will not remove childs automatically when the parent is removed. Or you must drop the integrity check (not recommended) so that you can (but will generate orphan records). Or you must first delete childs and then parent.

But this is guessing. Go to Application menu and set debug sql on. Then every sql statement is shown before execution and you will be able to see what’s going on and what’s actually the problem.

I had the same issue,
You said that you are trying to delete records on the master form, as Albert said make sure that the child records are gone first, but if you are having the same issue as I had…they were deleted already.
If you are using global variables and are trying to delete the master record I had to set the global variables in the BeforeDelete Event for example I had three global variables and had to set them before would allow me to delete i.e.

[FACILITY] = “”;
[CATEGORY] = “”;
[LAB_YEAR_DATA] = “”;

then I could delete the master record.

thought could be issue, but without much else, was a guess by me.

Hope that helps…

Kevin

yes! that’s it. whenever i remove the records in master i am also deleting my records in child forms on AfterDelete Event. so i guess i will try adding the delete in BeforeDelete Event then let’s see if it’ll work.

I noticed that when i delete a record the code in afterDelete event is actually working, but then this error message shows. then i have to delete the record in master form again to successfully delete it.

anyway i’ll try your comments. thank u!

It worked! im deleting the records from detail form on OnBeforeDelete event! thank u very much guys

Yes, using onafterdelete means that you delete the master first and then the childs. Great it is solved now.