DoCmd.RunSql "Delete..." doesn't work

odrap

Registered User.
Local time
Today, 11:14
Joined
Dec 16, 2008
Messages
156
On the form frmOrders i have a button to delete the current order in tblOrders, if no corresponding orderitems exists anymore in tblOrderdetails.
To delete the orderrecord, i use the following code:

Application.Echo False
Call TglVergrendeling(Me, SECTION_DETAIL, False) (= unlocking the controls)
Me.AllowDeletions = True
DoCmd.RunSQL "DELETE * From " & "tblOrders" & " Where [OrderID] = Forms!frmOrders![OrderID];"

After running this code, the data of the deleted order remains visible in the form, the order isn't deleted.
If i add the following code after the runSql hereabove,
Me.requery
i get the following message:
someone else deleted the record.

I could use cascading deletion, but the user of the program prefer to get the possibility to make a choice after deleting all orderitems of an order:
keeping the ordernumber and immediatly entering other orderitems, or deleting the order in the table tblOrders.
 
Actually, this part:
DoCmd.RunSQL "DELETE * From " & "tblOrders" & " Where [OrderID] = Forms!frmOrders![OrderID];"
should be like this:

DoCmd.RunSQL "DELETE * From " & "tblOrders" & " Where [OrderID] =" & Forms!frmOrders![OrderID]

And I would use

CurrentDb.Execute

instead of

DoCmd.RunSQL
 
I'm pretty sure you can use cascading deletions without the warning.

Try and write a query to delete an order, with cascading deletion enabled. then call that query with this code:

Code:
CurrentDb.Execute <NameOfQuery>, dbFailOnError
 
I tried each of the suggestions you sent me, but without success.
The order can't be deleted.
Any other idea what can be the reason for this behaviour?
 
I tried each of the suggestions you sent me, but without success.
The order can't be deleted.
Any other idea what can be the reason for this behaviour?

1. are you sure that all order details have been deleted before trying to delete the upper level order?

2. If you are on a bound form then after the details have been deleted and the person wants to delete the parent order, just use

DoCmd.RunCommand acCmdDeleteRecord

to delete the current record (no delete query is required).
 
Thank yoy very much for the help!
Your last suggestion works very fine!!!
Greetings from Brugge in Belgium
 

Users who are viewing this thread

Back
Top Bottom