I’m using ADO to delete a record in my MS Access 2007 database and am at a total loss as to why I’m getting this syntax error for my SQL code. It claims there is an error in the FROM clause but I do not see it. I have taken the FROM clause directly from a working SQL statement in another module using the same table. I’ve entered the code into the SQL View of a new query and it runs just fine. Here is the code:
Private Sub cmdDeleteMessage_Click()
If MsgBox("Once you delete a message, it cannot be undone." & _
"Are you sure you want to delete this message?", vbYesNo) = vbYes Then
Dim sql As String
Dim rsDel As New ADODB.Recordset
rsDel.CursorType = adOpenDynamic
rsDel.LockType = adLockOptimistic
sql = "DELETE * FROM [Staff Notes] WHERE [MsgID] = " & Me.txtMsgID.Value & ";"
rsDel.Open sql, CurrentProject.AccessConnection, , , adCmdTable
With rsDelete
.Update
.Close
End With
End If
End Sub
And Ideas? Thanks in advance!
You’re trying to run an action query but using a recordset (which expects a select query).
Try this:
Also, if [MsgID] is a string, you need to enclose your value in quotes: