The following ignores Ctrl+F and Ctrl+H as an example, paste this into a Module:
Global gControlKeyPressed As Boolean
Global gCancelKeyPress As Boolean
Public Function ControlKeyDown(K_Code As Integer)
If K_Code = vbKeyControl Then
gControlKeyPressed = True
End If
If gControlKeyPressed = True Then
Select Case K_Code
Case vbKeyF 'Find
gCancelKeyPress = True
Case vbKeyH 'Replace
gCancelKeyPress = True
Case Else
gCancelKeyPress = False
End Select
End If
End Function
Public Function ControlKeyUp(K_Code As Integer)
If K_Code = vbKeyControl Then
gControlKeyPressed = False
End If
End Function
In each form that you want to use this, paste:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
ControlKeyDown (KeyCode)
If gCancelKeyPress = True Then
KeyCode = 0
gCancelKeyPress = False
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
ControlKeyUp (KeyCode)
End Sub
Also in each form, set its Key Preview to Yes. You can add as many Ctrl+Key combinations as letters in the alphabet to the above.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.