Can't disable keystroke shortcut

  • Thread starter John S. Ford, MD
  • 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
 
T

Tom Wickerath

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
 
A

Albert D. Kallal

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top