Jeff said:
Hello,
Is their any way to disable when a User hits any Function Key ?
Especially F12 when a Form is Open (prompts to Save that Form to a Differnt
Name)
I tried trapping them in the KeyDown Event but I cant get it to work...
I tried...
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode >= 112 and KeyCode <= 123 then KeyCode = vbNull
End Sub
Basically again what I am looking for is when any Form is Open to not allow
any of the Function Keys to be hit.
Thank you,
Jeff
Jeff said:
Hello,
Is their any way to disable when a User hits any Function Key ?
Especially F12 when a Form is Open (prompts to Save that Form to a Differnt
Name)
I tried trapping them in the KeyDown Event but I cant get it to work...
I tried...
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode >= 112 and KeyCode <= 123 then KeyCode = vbNull
End Sub
Basically again what I am looking for is when any Form is Open to not allow
any of the Function Keys to be hit.
Thank you,
Jeff
Jeff said:
Hello,
Is their any way to disable when a User hits any Function Key ?
Especially F12 when a Form is Open (prompts to Save that Form to a Differnt
Name)
I tried trapping them in the KeyDown Event but I cant get it to work...
I tried...
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode >= 112 and KeyCode <= 123 then KeyCode = vbNull
End Sub
Basically again what I am looking for is when any Form is Open to not allow
any of the Function Keys to be hit.
Thank you,
Jeff
Access 2003 Help (KeyPreview Property):
Example
In the following example, the KeyPreview property is set to True in the form's Load event procedure. This causes the form to receive keyboard events before they are received by any control. The form KeyDown event then checks the KeyCode argument value to determine if the F2, F3, or F4 keys were pushed.
'----------------------------------
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
'----------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF2
'Process F2 key events.
Case vbKeyF3
'Process F3 key events.
Case vbKeyF4
' Process F4 key events.
Case Else
End Select
End Sub
....or:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_KeyDown
Dim intCtrlDown As Integer, intAltDown As Integer, intShiftDown As Integer
intCtrlDown = (Shift And acCtrlMask) > 0
intAltDown = (Shift And acAltMask) > 0
intShiftDown = (Shift And acShiftMask) > 0
'Disable F12 (Save), F7 (Spelling), F5 (Refresh), F1(Help), ESC (undo)
If KeyCode = vbKeyF12 Or KeyCode = vbKeyF7 Or KeyCode = vbKeyF5 Or _
KeyCode = vbKeyF1 Or KeyCode = vbKeyEscape Then
KeyCode = 0
End If
'Disable CONTROL + F4, CONTROL + W, CONTROL + H (Replace), CONTROL + P (Print)
'CONTROL +O (Open), CONTROL + F (Find), CONTROL + N (New), CONTROL + Z (undo)
If intCtrlDown Then
If KeyCode = vbKeyF4 Or KeyCode = vbKeyW Or KeyCode = vbKeyH Or _
KeyCode = vbKeyP Or KeyCode = vbKeyO Or _
KeyCode = vbKeyN Or KeyCode = vbKeyZ Then
KeyCode = 0
ElseIf KeyCode = vbKeyF Then
KeyCode = 0
DoCmd.OpenForm "frm_Search"
Else
End If
End If
'Disable keyboard close application ALT +F4
If intAltDown Then
If KeyCode = vbKeyF4 Then
KeyCode = 0
Else
Exit Sub
End If
End If
'Disable SHIFT + F4, SHIFT + F1 (help / ?)
If intShiftDown Then
If KeyCode = vbKeyF4 Or KeyCode = vbKeyF1 Then
KeyCode = 0
Else
End If
End If
Exit_Form_KeyDown:
Exit Sub
Err_Form_KeyDown:
MsgBox "Err_Form_KeyDown " & Err.Number & ": " & Err.Description
Resume Exit_Form_KeyDown
End Sub
Note that you can assign your own actions:
.......
If intCtrlDown Then
if intAltDown then
If KeyCode = vbKeyM
KeyCode = 0 'Disable ctrl + alt + M
RunCommand acCmdAppMinimize 'instead, minimize application
End if
End If
End If
.......
HTH,
Damir