Results 1 to 3 of 3

Thread: Error 3021

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Posts
    98

    Error 3021

    Im getting the following error

    "3021 Either BOF or EOF is True, or the current record has been deleted.Requested operation requires a current record."

    ----------

    This is my code

    With rs
    .Open strSQL, cn, adOpenDynamic, adLockOptimistic
    .Delete
    End With

    rs.MoveNext
    If rs.EOF Then
    rs.MoveLast
    End If

    ----------

    I thought I took care of this error with the movenext and rs.eof check. What did I do wrong?

    Thanks,

    coopetj

  2. #2
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121
    I think that before you delete a certain record within a recordset, that record have to be the current one. You invoked the deletion before positioning on a particular record. So, assuming that you want to delete the first record, you should do that :
    Code:
    With rs 
    .Open strSQL, cn, adOpenDynamic, adLockOptimistic 
    .MoveFirst
    .Delete 
    End With
    But if you want to delete some other record than the first one, then you move to that record and only after you did that you call the deletion.
    I hope this did help.
    Surgeon

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Also check for the .EOF and .BOF before you try to delete any records, in this way you will be saved if the recordset is empty.

    'Open recordset
    'If BOF and EOF both true, the recordset is empty, so get the hell out of here.
    'Recordset is not empty, so move to the desired record
    'Delete the record.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width