Still suffering from Delete runtime error 3021

Wegets7

Registered User.
Local time
Today, 11:42
Joined
Oct 18, 2004
Messages
40
I'm using a Access Xp 2002 and Keep getting this error when I delete a record. The error is Run Time Error 3021 "No Current record". The error started after I exported all my forms, queries and reports to a split off of the database. The delete still occurrs it just produces this error.

Any help would be greatly appriciated. Rich

Here is the code:

Private Sub StudentDelete_Click()
On Error GoTo Err_StudentDelete_Click

strMessage = "Are you sure you want to delete the student, " & [FirstName] & " " & [LastName] & " "
Style = vbCritical + vbYesNo
strTitle = "Delete Record?"
Response = MsgBox(strMessage, Style, strTitle)


DoCmd.SetWarnings False

If Response = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Else
Exit Sub
End If

DoCmd.SetWarnings True

Exit_StudentDelete_Click:
Exit Sub

Err_StudentDelete_Click:
If Err <> 3021 Then
MsgBox Err.Description
Resume Exit_StudentDelete_Click
End If

End Sub
 
I dont even use the line:

DoCmd.RunCommand acCmdSelectRecord

and never get this error. (Using A2000)

Dave :confused:
 
There's a few other flaws in the code - notably that the warnings aren't turned on again if the user selects No and the variables and constants are not defined. You should put Option Explicit at the very top of your modules, the benefits of which will become clear.

Code:
Private Sub StudentDelete_Click()
    On Error GoTo Err_StudentDelete_Click

    Const strMessage As String = "Are you sure you want to delete the student, "
    Const intStyle As Integer = vbQuestion + vbYesNo + vbDefaultButton2
    Const strTitle As String = "Delete Record?"
    Dim bytResponse As Byte

    bytResponse = MsgBox(strMessage & Me.FirstName & " " & Me.LastName, intStyle, strTitle)

    If bytResponse = vbYes Then
        With DoCmd
            .SetWarnings False
            .RunCommand acCmdDeleteRecord
            .SetWarnings True
        End With
    End If

    Exit Sub

Err_StudentDelete_Click:
    If Err.Number <> 3021 Then MsgBox Err.Description, vbExclamation, "Error #" & Err.Number

End Sub
 
Thanks SJ, Oldsoftboss.
No luck. I implemented the code as SJ posted it and still get the alarm.

I'm wondering if the way I split the database may be the problem. I first split off the tables to a new file and then exported the forms, queries, reports and macros to the file to get rid of a code module that was crreating problems.

Does this seem likely?
Rich
 
Last edited:
Comment out this line: On Error GoTo Err_StudentDelete_Click.

Run the code. What line does the code stop at? And what's the message you get?
 
After commenting out the on error GoTo statement I get
"Run time error 3021 - No current record"
And debug stops at .RunCommand acCmdDeleteRecord

Thanks again
Rich :o
 
Last edited:
Does your form have a RecordSource?

It sounds to me then that you may be just selecting something in a listbox or combo and pressing a button to delete it while the record isn't actually in the form.
 
I believe it does have a valid RecordSource. I'm building a single user database with a form I use to create a student that is bound to the Student table. The delete button is on this form and completes the deletion. The form has four fields, an auto number, and three text fields for student id and name. If I cursor through the records and randomly delete a student, with the focus on the autonumber, the record disappears after the prompt and the error message appears. If I choose Debug it points to the delete command. If I choose End the form resumes functioning.

I could ignore this problem, unfortunatly my user can't.
Thanks again.
Rich
 
Last edited:
Can you upload an example of this?
 
Here is the current version on the database. The Student entry form has the code I've been working on though other delete modules produce the same error.

Thanks Rich
 
Wegets7 said:
Here is the current version on the database. The Student entry form has the code I've been working on though other delete modules produce the same error.

Thanks Rich
Attempt number 2
 
If it's too large then compact it, .zip it up, and try again. Otherwise PM me and I'll give you an email address to forward it to.
 
I guess even zipped the database is to large at 600kb. Any other suggestion? I don't know any other way to demonstrate this.

Rich :(
 
I've sent you an email address to send it to via a Private Message.
 
does it work manually...

HI,

I had a similar problem with this... does the form let you delete the record manually. This will tell you if it's a coding error or something wrong with thesetup...

If the form doesn't let you do it in form view, does it let you in datasheet view. If it doesn't let you in either, you may have got ALLOW DELETIONS setting turned to no....
 
The deletion occurs its just that I get an error message "Run time error 3021 - No current Record" afterward.
 
What form should I be looking at?
 
Sorry the 2__STUDENT_ENTRY_REGISTRATION form has the code we've looked at thus far. The error mesage occurrs in other delete methods

Rich
 
OKay, I found the form and tried it and, you're going to love this...it worked for me without any problems. I am also using Office 2002 with Windows XP.

Looking at the code throughout the database though I can see a big problem - you've used the command button wizards to do a lot of tasks and these, due to Microsoft's laziness, were code snippets that had a great significance in Access 95 but mean little today and are only used for backwards compatibility i.e. the wizards generate defunct code.

Also, the reason you couldn't reduce the size of the database was because it has a quantity of bitmap images which significantly add to the database's overall size.
 

Users who are viewing this thread

Back
Top Bottom