Can't disable keystroke shortcut

  • Thread starter Thread starter John S. Ford, MD
  • Start date Start date
J

John S. Ford, MD

I'm working in Access 97 and am trying to write some code to disable some
keystroke shortcuts, particularly <Ctrl> + Minus which will allow users to
delete records that I don't want them to delete. I've set the key preview
property of the form and it's embedded subform to Yes. I've placed the
following code in both the form and subform:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim CtrlDown As Integer
CtrlDown = (Shift And acCtrlMask) > 0
If CtrlDown And KeyCode = vbKeySubtract Then
KeyCode = 0
End If
End Sub

If I have the cursor on the subform and I hit <Ctrl> + Minus, the current
record STILL gets deleted. Any ideas as to what I'm doing wrong?

John
 
Hi John,

Why not just set the Allow Deletions property for the form to No?


Tom
_________________________________________


I'm working in Access 97 and am trying to write some code to disable some
keystroke shortcuts, particularly <Ctrl> + Minus which will allow users to
delete records that I don't want them to delete. I've set the key preview
property of the form and it's embedded subform to Yes. I've placed the
following code in both the form and subform:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim CtrlDown As Integer
CtrlDown = (Shift And acCtrlMask) > 0
If CtrlDown And KeyCode = vbKeySubtract Then
KeyCode = 0
End If
End Sub

If I have the cursor on the subform and I hit <Ctrl> + Minus, the current
record STILL gets deleted. Any ideas as to what I'm doing wrong?

John
 
Try:

If ctrlDown And KeyCode = 189 Then
KeyCode = 0
End If

I think vbKeySubtract is ONLY for the number pad key...I could not find a
ref, so I just put in a debug-print, whacked the ctrl key
to come up with the above number....
 
Back
Top