Upon clicking Delete to delete the current record on frmTopics, I want several things to happen:
1) Display a custom message rather than Access's standard "You are about to delete n records" one.
2) Delete the record.
3) Delete all related attribute records.
4) Go to a new record.
Here is my code:
The record is successfully deleted, and Access's standard message suppressed (is there a better way?) but there is the following problem:
When there are related attribute records that could be deleted, I get a "syntax error in FROM clause error" and the line CurrentDb.Execu te strSQL, dbFailOnError is highlighted in my VBA code. I tried this out as a plain query, which worked, and then dropped it into this "formula." Maybe I just missed a quote or something, although I have tweaked it every way I can think of. This issue is somewhat related to my other thread about creating a new record and related records--the concatenation principle--which I now understand in theory, although apparently not in practice :)
1) Display a custom message rather than Access's standard "You are about to delete n records" one.
2) Delete the record.
3) Delete all related attribute records.
4) Go to a new record.
Here is my code:
Code:
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click
DoCmd.SetWarnings (False)
Dim strMsg As String
strMsg = "Are you sure you want to delete this topic? You cannot undo a deletion."
If MsgBox(strMsg, vbOKCancel) = vbOK Then
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.GoToRecord , , acNewRec
Dim strSQL As String
strSQL = "DELETE * FROM tblTopicAttributes" & "WHERE tblTopicAttributes.top_id=" & Forms!frmTopics!nbrTopID & ";"
CurrentDb.Execute strSQL, dbFailOnError
Else
Me.Undo
End If
Exit_cmdDelete_Click:
Exit Sub
Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click
DoCmd.SetWarnings (True)
End Sub
When there are related attribute records that could be deleted, I get a "syntax error in FROM clause error" and the line CurrentDb.Execu te strSQL, dbFailOnError is highlighted in my VBA code. I tried this out as a plain query, which worked, and then dropped it into this "formula." Maybe I just missed a quote or something, although I have tweaked it every way I can think of. This issue is somewhat related to my other thread about creating a new record and related records--the concatenation principle--which I now understand in theory, although apparently not in practice :)
Comment