Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-11-08
5
Medium Priority
?
1,190 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 2000 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 93

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

636 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