|
-
Oct 3rd, 2000, 04:00 PM
#1
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
-
Oct 3rd, 2000, 04:58 PM
#2
Fanatic Member
What is the TestCode object? Is it the name of a form? As if so; did you remember to set the KeyPreview property for the form to True? That way you should be able to force the form to fire it's KeyUp event before any of the controls or anything.
-
Oct 3rd, 2000, 05:06 PM
#3
_______
<?>
Code:
Option Explicit
'yes/no of a msgbox
Private Sub Command1_Click()
Dim strMsg As VbMsgBoxResult
strMsg = MsgBox("Really quit?", vbYesNo)
If strMsg = vbNo Then
Exit Sub
'do nothing or add your code
Else
'unload me..you would call your delete function
Unload Me
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 4th, 2000, 01:52 PM
#4
The test code object is a textbox, linked to the db.
But I was able to get it to work thanks for your help guys.
Homer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|