Delete is not happening

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
 
J

John W. Vinson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top