Getting "3021" Error when using Recordset.find

Posted on 2005-04-26
Last Modified: 2013-12-25
I'm connecting to an .MDB file through ADO with VB6, and setting a DataGrid's datasource to my recordset.

I'm having a problem when using recordset.find.
If I try to search (using recordset.find) for a record that matches a record in the recordset located before the current record/cursor location, I get the following error:

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

So I can search successfully so long as the matching record is located *after* the currently selected record. When I search for a record located before the current one, I get the above error the moment I try and do something with the record...

I'm fairly new to DB programming with VB, and any help would be much appreciated... Thanks.
Question by:Melvinivitch
    LVL 8

    Expert Comment

    so make sure recordset contain data before u search throught recordset.
    if u search empty recordset then this err will occur.

    if recordset.bof = true and recordset.eof = true then
       msgbox "No recordset for search"
       exit sub
      recordset.find "field=data"
    end if

    Author Comment

    Thanks for the reply...

    I do have data in my recordset.

    I realized that when I do recordset.moveFirst  before the recordset.find, I don't get the error... This may be obvious, but being new to using these objects, I hadn't figured that one out yet...
    LVL 8

    Accepted Solution

    always do a recordset.movefirst before the find. this sets the cursor location at the top of the recordset. if you get eof then the search came back empty. for some reason the find method wont move the cursor to the top of the recordset even if you use the
    start parameter in the function.
    Recordset.Find (criteria, SkipRows, searchDirection, start)

    just do:

    recordset.find "field=data"

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now