Edit, Delete, Update ... Error :-(

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hello People,

Using MS Access 2003 VBA I get the error 3020 Update or CancelUpdate
without AddNew or Edit when I run through the following code. Can
anyone help suggest anything to try? Thanks.

On Error GoTo delete_failed

Dim RS_DEL As DAO.Recordset

Dim DB As DAO.Database

Set DB = CurrentDb

' Delete Row in Nodes_T table

Set RS_DEL = DB.OpenRecordset("SELECT * FROM Nodes_T WHERE [Record_ID]
=" & Me.Record_ID, dbOpenDynaset, dbSeeChanges)

If RS_DEL.RecordCount = 1 Then

' If found record with correct record ID, DELETE IT

RS_DEL.Edit
RS_DEL.Delete
RS_DEL.Update

RS_DEL.Close
DB.Close
Set RS_DEL = Nothing

End if
 
Your code should be something like

Set DB = CurrentDb

' Delete Row in Nodes_T table

Set RS_DEL = DB.OpenRecordset("SELECT * FROM Nodes_T " _
& "WHERE [Record_ID]=" & Me.Record_ID, _
dbOpenDynaset, dbSeeChanges)

If RS_DEL.RecordCount = 1 Then
RS_DEL.Delete
End if
RS_DEL.Close
DB.Close
Set RS_DEL = Nothing

But wouldn't it be easier to just

Set DB = CurrentDb
DB.Execute "DELETE * FROM Nodes_T " _
& "WHERE [Record_ID] =" & Me.Record_ID
 
Back
Top