Still suffering from Delete runtime error 3021 (1 Viewer)

Wegets7

Registered User.
Local time
Today, 10:02
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
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 04:02
Joined
Oct 28, 2001
Messages
2,504
I dont even use the line:

DoCmd.RunCommand acCmdSelectRecord

and never get this error. (Using A2000)

Dave :confused:
 

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
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
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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:

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
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?
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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 :eek:
 
Last edited:

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
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.
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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:

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
Can you upload an example of this?
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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
 

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
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.
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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 :(
 

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
I've sent you an email address to send it to via a Private Message.
 

Simplycongy

Registered User.
Local time
Today, 17:02
Joined
Nov 8, 2004
Messages
43
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....
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
The deletion occurs its just that I get an error message "Run time error 3021 - No current Record" afterward.
 

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
What form should I be looking at?
 

Wegets7

Registered User.
Local time
Today, 10:02
Joined
Oct 18, 2004
Messages
40
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
 

Mile-O

Back once again...
Local time
Today, 17:02
Joined
Dec 10, 2002
Messages
11,316
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

Top Bottom