vba 运行时错误 3021 - EOF 或 BOF 为真或当前记录已被删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20532259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run time error 3021 - EOF or BOF is true or the current record has been deleted
提问by user2898085
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.
我收到运行时错误 3021 但查询不为空。
回答by HansUp
"I receive the runtime error 3021 however the query is not empty."
“我收到运行时错误 3021,但查询不为空。”
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.
如果该版本的代码告诉您“记录集为空”,请转到立即窗口 ( Ctrl+ g) 以检查SELECT
代码构建的语句。您可以复制语句文本并将其粘贴到新 Access 查询的 SQL 视图中以进行测试。
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
:
我最好的猜测是查询不返回任何行,因为它在 的值之前包含一个空格idtask
,并且没有[ID - Tarefa]
值匹配 space plus idtask
:
idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );"
^ here