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
我收到运行时错误3021,但查询不为空。
答案 0 :(得分:6)
“我收到运行时错误3021,但查询不为空。”
仔细检查这一点。
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
如果该版本的代码告诉您“记录集为空”,请转到立即窗口( Ctrl + g )进行检查代码构建的SELECT
语句。您可以复制语句文本并将其粘贴到新的Access查询的SQL视图中以进行测试。
我最好的猜测是查询不返回任何行,因为它在idtask
的值之前包含一个空格,并且没有[ID - Tarefa]
值与空格加idtask
匹配:
idfunc & "' AND [ID - Tarefa] LIKE ' " & idtask & "' );"
^ here