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:
•Check if specific record exists
•Master-details relationship between tables