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,175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

738 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