Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error code 3021 either bof or eof is true or the current record has been deleted

Tags:

vba

ms-access

I have an Access 2003 database with some visual basic code using ADO calls in it. When I do a

strsql0 = "SELECT lnk_stockitm.C_C FROM lnk_stockitm WHERE (((lnk_stockitm.C_C) Like 'T*'));"
newRS.Open strsql0, cn1, adOpenKeyset, adLockReadOnly  
newRS.movelast

I get this error:

3021 either bof or eof is true or the current record has been deleted

When I run the exact same query in the same function without the WHERE clause, like this:

strsql0 = "SELECT lnk_stockitm.C_C FROM lnk_stockitm;

I get the correct result of 56,000 records. If I paste the full SQL statement with the WHERE clause into a regular query, like so:

SELECT lnk_stockitm.C_C FROM lnk_stockitm WHERE (((lnk_stockitm.C_C) Like 'T*'));

it returns the correct subset of the results (2800 records).

Can anyone tell me what I am doing wrong?

like image 441
Colin Avatar asked Dec 02 '25 09:12

Colin


1 Answers

The wildcard difference is the cause for difference between what you execute from ADO and within your access database. Convert your statement to use "%" rather than "*". As a general rule of thumb, it may be a good idea to encapsulate your code by checking for eof before calling MoveLast. If your query has zero results it'll bomb out every time.

strsql0 = "SELECT lnk_stockitm.C_C FROM lnk_stockitm WHERE (((lnk_stockitm.C_C) Like 'T*'));"
newRS.Open strsql0, cn1, adOpenKeyset, adLockReadOnly  

if not newRs.eof then
   newRS.movelast
else
  ' do something here if necessary to handle blank results
end if
like image 54
Jakkwylde Avatar answered Dec 04 '25 04:12

Jakkwylde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!