Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Control + (key) options 1

Status
Not open for further replies.

rphbrew

Technical User
Nov 30, 2002
40
US
How do I keep people from using the keyboard commands in my Access 97 Database?

I want to force people to use the buttons on the forms.

thanks
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top