Solved

Run-time error 3021; Either BOF or EOF is true or the current record has been deleted

Posted on 2010-11-08
5
1,174 Views
Last Modified: 2013-11-27
Hi, I get the following error in our database when we run the below code which is designed just to remove a customer from our table.

Any ideas on what this might be; I have tried on two different machines; both XP Pro SP3 with Access 2003.

Many Thanks

Private Sub TerminateContract(clientID, dteDate)

    Dim cnArray(9) As Variant
    Dim x As Integer
    x = 0
       
    Set cnn = CurrentProject.AccessConnection
    Set rst = New ADODB.Recordset
           
    With rst
   
        Set .ActiveConnection = cnn
            .Source = "tbl_cnDetails"
            .LockType = adLockOptimistic
            .CursorType = adOpenDynamic
            .CursorLocation = adUseServer
            .Open
           
            If .BOF Or .EOF = True Then GoTo Exit_Procedure
       
            .MoveFirst
            Do Until .EOF
               
                If .Fields("fld_cnClientID") = clientID Then
                                   
                     cnArray(0) = .Fields("fld_cnClientID")
                     cnArray(1) = .Fields("fld_cnContractStartDate")
                     cnArray(2) = .Fields("fld_cnContractRenewalDate")
                     cnArray(3) = .Fields("fld_cnSchedule1")
                     cnArray(4) = .Fields("fld_cnFee")
                     cnArray(5) = .Fields("fld_cnWetPercentage")
                     cnArray(6) = .Fields("fld_cnDryPercentage")
                     cnArray(7) = .Fields("fld_cnSpecialAgreement")
                     cnArray(8) = dteDate
                   
                End If
            .MoveNext
            Loop
            .Close
           
            .Source = "tbl_cnHistory"   ' Add contract details to cnHistory table.
            .Open
            .AddNew
            For x = 0 To 8
                .Fields(x) = cnArray(x)
            Next x
            .Update
            .Close
           
            .Source = "tbl_cnPending"   ' Delete contract from cnPending if there is one.
            .Open
            .MoveFirst
            Do Until .EOF
                If .Fields("fld_cnPendingClientID") = clientID Then
                    .Delete
                End If
                .MoveNext
            Loop
            .Close
           
            .Source = "tbl_cnDetails"   ' Delete contract from Contract Details table.
            .Open
            .MoveFirst
            Do Until .EOF
                If .Fields("fld_cnClientID") = clientID Then
                    .Delete
                End If
                .MoveNext
            Loop
           
    End With
   
Exit_Procedure:
    rst.Close
    Exit Sub

End Sub
0
Comment
Question by:chrisbarr35
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 34083379
Which line produces the error?
0
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 34083431
Hi,

beyond the question where the error occurs:

Why don't you simply use a DELETE-SQL-Command to delete the record(s)?
Why don't you simply use referential integrity to automatically delete the contract details?
Why don't you use a INSERT SELECT-Command to copy the data to the history?

The complete procedure would be a few lines only and a lot of faster.

Cheers,

Christian
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 34127535
I agree with Bitsqueezer -- was about to post a similar comment.  

0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 34840102
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question