I am trying to prevent a records from being deleted, and whish to produce a message box when the delete key is pressed.

This is the code that I am using:

************************************************************

Sub TestCode_KeyUp (KeyCode As Integer, Shift As Integer)
'On Error Resume Next
On Error GoTo KeyPressErr

Dim Launch As Integer
Const vbYesNo = 4
Const vbExclamation = 48
Const vbYes = 6
Const vbNo = 7
Const SHIFT_MASK = 1
Const CTRL_MASK = 2
Const ALT_MASK = 4
Dim ShiftDown, AltDown, CtrlDown, KeyPressed
ShiftDown = (Shift And SHIFT_MASK) > 0
AltDown = (Shift And ALT_MASK) > 0
CtrlDown = (Shift And CTRL_MASK) > 0
If KeyCode = 119 Then
If CtrlDown Then
If Me![Sel] = -1 Then
DoCmd OpenForm "SAMPLE_SEL", A_formds, , "SampTestNo = " & Me!SampTestNo & ""
End If
End If
ElseIf KeyCode = 46 Then
If Me!TestGroup <> 0 Then
If MsgBox("This Test is part of a Testgroup. Are you sure that you whish to delete it?", vbYesNo + vbExclamation, "Warning") = vbNo Then
DoCmd CancelEvent
End If
End If
End If
Exit Sub

KeyPressErr:
MsgBox Error$ & ":" & Err
Resume Next

End Sub

************************************************************


However nothing happens. What have I done wrong? I thought that this was a simple thing to do?

Thanks in advance.
Homer Youngblood