I have a form that has parent records (tblQuestions) with a subform of child records (tblQuestResponseSets) that has a button to allow the user to delete a parent record (a question) and write a copy of the delted record to another table. Each question has related child records (responses). I am trying to write code that will delete the child records along with the parent record when the delete command button is selected by the user. The attached code is working fine in that it is deleting the parent record and copying the parent record to the appropriate table and it is also copying the child records appropriately. What it is not doing is deleting the child records. I know I have something wrong in my code but not sure how to get it to work. Thanks for any help you may lend.
Private Sub cmdDelete_Click()
'Deletes current record from tblQuestions and saves a copy in tblDeleteQuestions
'Deletes child records from tblQuestResponseSets and saves copy in tblDeleteQuestResponseSets
On Error GoTo Err_cmdDelete_Click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.RunSQL "INSERT INTO [tblDeleteQuestions] SELECT * FROM [tblQuestions] WHERE [QuestID] = QuestIDfrm"
DoCmd.RunSQL "INSERT INTO [tblDeleteQuestResponseSets] SELECT * FROM [tblQuestResponseSets] WHERE [QuestID] = QuestIDfrm"
DoCmd.RunSQL "DELETE FROM [tblQuestions] WHERE [QuestID] = QuestIDfrm"
DoCmd.RunSQL "DELETE FROM [tblQuestResponseSets] WHERE [QuestID] = QuestIDfrm"
DoCmd.Close acForm, "frmQuestionDetail"
stDocName = "frmQuestionSummary"
DoCmd.OpenForm stDocName, , , stLinkCriteria