ACC1x: How to Disable PAGE UP and PAGE DOWN Keys in a Form (1.x)

Last reviewed: April 24, 1997
Article ID: Q114504
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1

SUMMARY

This article describes the following two techniques that you can use to disable the use of the PAGE UP and PAGE DOWN keys in a form:

  • Open the form as a Dialog form using the OpenForm macro action.

    -or-

  • Use the Windows API GetKeyState() function call to trap the PAGE UP and PAGE DOWN keys.

NOTE: This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual in version 2.0.

CAUTION: Re-creating the examples in this article will modify the sample database NWIND.MDB. You may want to back up the NWIND.MDB file, or perform these steps on a copy of the NWIND database.

MORE INFORMATION

Method 1: Opening the Form as Dialog Using the OpenForm Macro Action

The PAGE UP and PAGE DOWN keys will be inoperative in a form if the form is opened using an OpenForm macro action with the Window Mode argument set to Dialog. To demonstrate this technique, create a new macro in the sample database NWIND.MDB with the following action:

   OpenForm
      Form Name: Customers
      Filter Name: <leave empty>
      Where Condition: <leave empty>
      View: Form
      Data Mode: Edit
      Window Mode: Dialog

The drawback to this technique is that a Dialog form cannot use a custom menu, nor will you be able to switch to another form while the dialog form is open.

NOTE: The Microsoft Access Wizards use this technique to limit navigation in multiple-page forms.

Method 2: Using the GetKeyState() API Call to Trap PAGE UP and PAGE DOWN

The following sample user-defined function, DisablePGUP_PGDN(), demonstrates how to use the GetKeyState() Windows API call to detect and trap the PAGE UP and PAGE DOWN keys. Attach this function to the OnExit property of all the controls on a form where the PAGE UP and PAGE DOWN keys should be disabled.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

  1. Create a new module with the following in the Declarations section:

          Option Explicit
          Global Const VK_PRIOR = &H21  ' PAGE UP
    
          Global Const VK_NEXT = &H22   ' PAGE DOWN
          Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
    
    

  2. Enter the following function in the module:

          Function DisablePGUP_PGDN()
    
             If GetKeyState(VK_PRIOR) < 0 Or GetKeyState(VK_NEXT) < 0 Then
                DoCmd CancelEvent
             End If
          End Function
    
    
To demonstrate the use of this function, open the Customers form in the NWIND.MDB database and alter the OnExit property of each control on the form to:

   =DisablePGUP_PGDN()

REFERENCES

For more information about the OnKeyPress function in version 2.0, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q114506
   TITLE     : ACC2: How to Disable PAGE UP and PAGE DOWN Keys in
               a Form (2.0)

Microsoft Access "Language Reference," versions 1.0 and 1.1, pages 348-349


Additional query words: pgup pgdn
Keywords : FmsOthr kbusage
Version : 1.0 1.1
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.