Delete is not happening

  • Thread starter Thread starter LAS
  • Start date Start date
L

LAS

I have a function, listed below. When I run it, gs_sql is equal to this
(cut from the debugger's view immediate window):

"Delete from tblStudentTracking where student_id = 384 and incident_date =
#10/18/2010# and Incident_Sequence =3"

When I execute the function, no error is registered. But neither is the row
deleted. When I paste the same statement in a Delete query, it deletes the
row fine. What could be wrong?

TIA
LAS

Private Sub cmdDelete_Click()

On Error GoTo Delete_Err

gs_sql = "Delete from tblStudentTracking where student_id = " &
Me!Student_ID _
& " and incident_date = #" & Me!Incident_date _
& "# and Incident_Sequence =" & Me!Incident_Sequence

Call CurrentDb.Execute(gs_sql)

Delete_Exit:
Exit Sub

Delete_Err:
MsgBox Error$
Resume Delete_Exit
End Sub
 
I have a function, listed below. When I run it, gs_sql is equal to this
(cut from the debugger's view immediate window):

"Delete from tblStudentTracking where student_id = 384 and incident_date =
#10/18/2010# and Incident_Sequence =3"

When I execute the function, no error is registered. But neither is the row
deleted. When I paste the same statement in a Delete query, it deletes the
row fine. What could be wrong?

TIA

You might be getting an error and not seeing it. Try using the dbFailOnError
argument to trap query errors:

Private Sub cmdDelete_Click()

On Error GoTo Delete_Err

gs_sql = "Delete from tblStudentTracking where student_id = " &
Me!Student_ID _
& " and incident_date = #" & Me!Incident_date _
& "# and Incident_Sequence =" & Me!Incident_Sequence

Call CurrentDb.Execute gs_sql, dbFailOnError

Delete_Exit:
Exit Sub

Delete_Err:
MsgBox Error$
Resume Delete_Exit
End Sub


This will transfer control to the Delete_Err code if there's any error in the
query.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/Forums/en-US/accessdev/
http://social.answers.microsoft.com/Forums/en-US/addbuz/
and see also http://www.utteraccess.com
 
Back
Top