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

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

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 is either bof or eof true or the current record has been deleted

When I run the same query in the same function without a WHERE clause, for example:

strsql0 = "SELECT lnk_stockitm.C_C FROM lnk_stockitm;

I get the correct result from 56,000 entries. If I insert the full SQL statement into the WHERE clause in a regular query, for example:

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

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

Can someone tell me what I am doing wrong?

+3
source share
2 answers

, ADO . "%", "*". , , eof MoveLast. , .

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
+5

"%" ADO.

MSDN: SQL

+5

Source: https://habr.com/ru/post/1722531/


All Articles