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

前端 未结 2 1414
野趣味
野趣味 2020-12-21 10:51

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 ((         


        
相关标签:
2条回答
  • 2020-12-21 11:10

    You need to use the '%' character as wildcard when using ADO.

    MSDN Article: Using the Right Wildcard Characters in SQL Statements

    0 讨论(0)
  • 2020-12-21 11:15

    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
    
    0 讨论(0)
提交回复
热议问题