Reputation: 49
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.
Upvotes: 1
Views: 28997
Reputation: 97101
"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
Upvotes: 7