Delete - No Record Selected

Wegets7

Registered User.
Local time
, 17:37
Joined
Oct 18, 2004
Messages
40
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 :)
 
You should not need this but give it a try...

Code:
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
 
ghudson said:
You should not need this but give it a try...

Code:
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

Thanks gHudson, but no noticeable change. :(
 
Just a thought...

Does your form have a valid recordsource?
 
Thanks Surjer
Yes, its a form bound to the table on a single user system and the deletion works. It seems to be erroring afterward like it's looking for another record. I've tried setting focus on the previous record after the delete command, but the error still appears.

R
Dayton Or.
:rolleyes:
 
Hi,
I have the same problem when I delete a record. Did you find out what was wrong or a way to "ignore" it.
/Karolina
 
As it turns out I found that the alarm only appeared on my win 98 machine and did not appear on my win xp laptop, your results may vary.

Below is a copy of a solution to the problem that I haven't tried yet. I was from someone name Mark from a different forum.

Code:
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 
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthcmdexecute.asp[/url] 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 
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthdeletex.asp[/url] 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
 

Users who are viewing this thread

Back
Top Bottom