I have troubles deleting records using the DoCmnd.RunSQL function.
Part of the application consist out of a form with a subform based on a 'parent' table called "kar" and a 'child' table called "lijst". The tables have a one to many relation.
The parent form contains a command button that appends the content of the current record (master and child) to other tables (this works), next the current record from 'kar' and records from 'lijst' should be deleted. Peace of cake I thought.
This is the code used:
This is the debug output:
Inversing the order of the deletes gives the same error for the last:
And the debug:
I inserted a 'gotorecord next' instruction before the first sqlzin= phrase but it makes no difference.
Clearly this is not a syntaxis issue because its always the second SQL operation that fails and the construction is ok : they run from the query view.
I do not want to use Enforce Referential Integrity with the Cascade Delete option (if possible) because it might limit manual interaction on the records.
So any idea what causes this behavior and ow to solve it?
Grateful for your effort!
Part of the application consist out of a form with a subform based on a 'parent' table called "kar" and a 'child' table called "lijst". The tables have a one to many relation.
The parent form contains a command button that appends the content of the current record (master and child) to other tables (this works), next the current record from 'kar' and records from 'lijst' should be deleted. Peace of cake I thought.
This is the code used:
The last DoCMD. RunSQL raises a runtime error 424 : object required.karWeg = Me.ID
sqlzin = "DELETE kar.* FROM kar WHERE ((kar.ID)= " & karWeg & ")"
Debug.Print sqlzin
DoCmd.RunSQL sqlzin
sqlzin = "DELETE lijst.* FROM lijst WHERE ((lijst_id)=" & karWeg & ")"
Debug.Print sqlzin
DoCmnd.RunSQL sqlzin 'Error on this line
This is the debug output:
If I copy the output from the last debug into a query SQL the record is deleted correctly (after resetting the code, Form still in the same condition)DELETE kar.* FROM kar WHERE ((kar.ID)= 22)
DELETE lijst.* FROM lijst WHERE ((lijst_id)=22)''
Inversing the order of the deletes gives the same error for the last:
Same error message.'line 2 and 5 swaped
karWeg = Me.ID
sqlzin = "DELETE lijst.* FROM lijst WHERE ((lijst_id)=" & karWeg & ")"
Debug.Print sqlzin
DoCmd.RunSQL sqlzin
sqlzin = "DELETE kar.* FROM kar WHERE ((kar.ID)= " & karWeg & ")"
Debug.Print sqlzin
DoCmnd.RunSQL sqlzin 'Error on this line
And the debug:
Again copying to an query as above works.DELETE lijst.* FROM lijst WHERE ((lijst_id)=23)
DELETE kar.* FROM kar WHERE ((kar.ID)= 23)
I inserted a 'gotorecord next' instruction before the first sqlzin= phrase but it makes no difference.
Clearly this is not a syntaxis issue because its always the second SQL operation that fails and the construction is ok : they run from the query view.
I do not want to use Enforce Referential Integrity with the Cascade Delete option (if possible) because it might limit manual interaction on the records.
So any idea what causes this behavior and ow to solve it?
Grateful for your effort!