Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Getting "3021" Error when using Recordset.find

Posted on 2005-04-26
Medium Priority
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

Expert Comment

ID: 13873357
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

ID: 13873686
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...

Accepted Solution

wraith821 earned 1000 total points
ID: 13875561
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

Industry Leaders: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

579 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