Help with error 3021

kaitiay

New member
Local time
Yesterday, 23:58
Joined
Oct 11, 2006
Messages
4
Hi, I'm learning Access on the fly for a temp job, and it's going pretty well, but I can't get past this problem:

I have a form for deleting a record, and it has a delete button with this code:

Private Sub Delete_Click()
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close acForm, "frmDelete"
End Sub

The record IS deleted, but the form is not closed. Instead, I get this message:

Run-time error 3021
No current record

I think I understand, logically, why this is happening - the counter at the bottom of the form is still set on record #x after x has been deleted, and it stops the code. But I can't for the life of me figure out how to fix it.

Thanks for your help!
 
theres probably an easier way but try putting this. Put me.requery after the delete command. this should requery the form, which will get rid of the deleted record. now the close should work
 
also try increashing the refresh of acces. think its set at something silly like a minute but u can reduce it to less so it updates the form sooner.
 
Thanks for your suggestions gemma and rborob - I tried both, but neither worked. Perhaps I'm attacking this from the wrong direction entirely? Back to google i go...
 
kaitlay:

When you are using this delete form, is it the one that has the records opened? Or, are the records opened on a different form and then you are opening that form to delete the record?

If the later is the case, you need to set the requery command to work on the OTHER form, not the delete form. So, in the delete form's code:
Code:
DoCmd.RunCommand acCmdDeleteRecord
Forms!YourMainFormNameHere.Requery
DoCmd.Close acForm, "frmDelete"

And, should that fail, you could possibly trap for error 3021 and just let it Resume Next after it traps it.
 
boblarson: There is only one form involved - the delete button is on the form that has the record open. Should that be changed?

I started learning VB the same time i started this project, a few days ago, but i will look up this "error trapping" of which you speak :-) Any pointers to a good tutorial on the subject are appreciated.
 
if resume next fixed your problem, then it seems to me that something funny is happening with the DELETE statement not with the CLOSE statement

looking at the code, you delete the record, which raises the error. handling the error returns you to the close statement.

if the delete was succeeding, and the close failing, resume next would not fix this.



so what is happening is your DELETE is failing. Are you trying to cancel the entry for a new record you have not saved yet. in that case the DELETE would fail as there is no current record to delete, and what you need is an UNDO event instead
 

Users who are viewing this thread

Back
Top Bottom