Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Forms: Disable PgUp/PgDown keys in a form

Author(s)
Dev Ashish

(Q)    How do I disable the Page Up/Page Down and other keys in my form?
(A)    Set the Form's Key Preview property to True and put the following code behind the OnKeyDown event. (The code disables the Alt and Tab keys as well.) Note that the Case Else statement, if uncommented, will print out the codes of any other keys you want to disable.

'************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'33 - PgUp; 34 - PgDown; 9 - Tab; 18=Alt
    Select Case KeyCode
        Case 33, 34, 9, 18
            KeyCode = 0
        Case Else
            'Debug.Print KeyCode, Shift
    End Select
End Sub
'************ Code End   **********

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer