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

ID: Q114504


The information in this article applies to:


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:

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:

Q114506 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          : kbusage FmsOthr 
Version           : 1.0 1.1
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 3, 1999