Run time error 3021 - EOF or BOF is true or the current record has been deleted

你离开我真会死。 提交于 2019-12-23 05:09:30

问题


rst.Open "SELECT * FROM Equipas WHERE ([ID - Funcionário] LIKE '" & idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
rst.Delete adAffectCurrent
rst.Update
rst.Close

I receive the runtime error 3021 however the query is not empty.


回答1:


"I receive the runtime error 3021 however the query is not empty."

Double check that point.

Dim strSelect As String
strSelect = "SELECT * FROM Equipas " & _
    "WHERE ([ID - Funcionário] LIKE '" & _
    idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );"
Debug.Print strSelect
rst.Open strSelect, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
If rs.BOF And rs.EOF Then
    MsgBox "recordset is empty"
Else
    rs.MoveLast
    MsgBox "recordset contains " & rs.RecordCount & " rows"
End If
'rst.Delete adAffectCurrent
'rst.Update
rst.Close

If that version of the code tells you "recordset is empty", go to the Immediate window (Ctrl+g) to examine the SELECT statement the code built. You can copy the statement text and paste it into SQL View of a new Access query for testing.

My best guess is the query returns no rows because it includes a space just before the value of idtask, and no [ID - Tarefa] values match space plus idtask:

idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );"
                                    ^ here


来源:https://stackoverflow.com/questions/20532259/run-time-error-3021-eof-or-bof-is-true-or-the-current-record-has-been-deleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!