Please enable JavaScript to view this site.

Navigation: Advanced topics > Events > Sample events > Database

Check for related records before deleting the current one

Scroll Prev Next More

 

Before deleting a record in the Orders table, check for related items in the OrderDetails table. Add the following code to the List page: Before record deleted event.

 

 

 

Function BeforeDelete(where,deleted_values)
' Parameters:
' where - string with WHERE clause pointing to record to be deleted.
dim rstmp  
set rstmp = dal.Table("Order_Details").Query("OrderID=" & _
    deleted_values("OrderID"),"")
if rstmp.eof then
   BeforeDelete = True
else
   BeforeDelete = False
 response.write "Order " & key &_
" has related records in Order Details table and cannot be deleted"
end if
 rstmp.Close : set rstmp = nothing
End Function

See also:

Data Access Layer

DAL method: TableName()

DAL method: Query

Database API

Check if specific record exists

Master-details relationship between tables