Delete - Error 3021: No current record

G

Guest

I'm using Access 2002 and after exporting all my working forms, queries,
macros and spitting off the database to get rid of one errant vba class
object, I now get
Error 3021: No current record
when I use a delete button on a a form that existed before the above
transformation. It also errors when I use a delete button created after the
transformation. Both delete functions complete successfully before the alarm
and when I use debug it points to the "DoCmd.RunCommand acCmdDeleteRecord"
statement.

Here is the code.

Private Sub StudentDelete_Click()
On Error GoTo Err_StudentDelete_Click

DoCmd.SetWarnings False

DoCmd.RunCommand acCmdDeleteRecord
Me.Refresh

DoCmd.SetWarnings True

Exit_StudentDelete_Click:
Exit Sub

Err_StudentDelete_Click:
If Err = 3021 Then 'No current record
MsgBox "Deletion Successful"
Exit Sub
Else
MsgBox Err.Description
Resume Exit_StudentDelete_Click
End If

End Sub

Any help would greatly appreciated
 
G

Guest

The delete has already occured by the time it gets to this code. I've had a
similar issue happen I use the DoCmd.CloseForm it closes the form and then
complains that it's already gone. I suggest deleting it in the recordset
instead of using DoCmd.

Mark

Both delete functions complete successfully before the alarm
 
A

Allen Browne

This is a known issue with Access 2002 Service Pack 3.

The error message - though annoying - is harmless. In the error handling
part of your code just ignore that number, i.e.:
If Err.Number <> 3201 Then
MsgBox Err.Description
End If
 
G

Guest

MarkInSalemOR said:
The delete has already occured by the time it gets to this code. I've had a
similar issue happen I use the DoCmd.CloseForm it closes the form and then
complains that it's already gone. I suggest deleting it in the recordset
instead of using DoCmd.

Mark

Thanks Mark. I'm just down the road from Salem.

Could you elaborate on "deleteing in the record set". I'm some what of a
newbe with Access/VBA and only have a vauge idea of what you mean.

Thanks Allen. Error trapping doesn't seem to make any difference. I tried it
both ways and the annoying alarm persists.
 
G

Guest

Except that it makes me as a developer look bad.

Allen Browne said:
This is a known issue with Access 2002 Service Pack 3.

The error message - though annoying - is harmless. In the error handling
part of your code just ignore that number, i.e.:
If Err.Number <> 3201 Then
MsgBox Err.Description
End If
 
G

Guest

Based on Allen's post it's a known bug and may be a problem regardless. I've
noticed the error handler gets sidestepped when running in the mdb but works
in an mde.

Try deleting it with one of these methods.

Create a delete query. Use the Access query builder, go to the SQL view,
copy it out and use it as your recordsets source. You'll need to replace
fixed values with variables.
"WHERE Example.KeyID =" & intID
You would use the execute command for this.
ado.recordset.execute
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthcmdexecute.asp for the details on this.

Or
This would be my preference but the query works fine too. If your backend
tables are on something other than a Microsoft product you may want to use
the query method.

ado.recordset.delete

see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthdeletex.asp for a complete how-to

Sorry it took me so long to get back to you on this. I've set my notify on
replies so I can get right back if you have more questions.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top