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,176 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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