Help and Support
 

powered byLive Search

ACC2: How to Disable PAGE UP and PAGE DOWN Keys in a Form

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:114506
Last Review:November 6, 2000
Revision:1.0
This article was previously published under Q114506
On This Page

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes the following two methods that you can use to disable the PAGE UP and PAGE DOWN keys in a form:
Open the form as a Dialog form using the OpenForm macro action.

-or-
Trap the PAGE UP and PAGE DOWN keys in the KeyDown event.

Back to the top

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 and run a new macro with the following actions in the sample database NWIND.MDB.
   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.

Back to the top

Method 2: Trapping PAGE UP and PAGE DOWN in the KeyDown Event

The PAGE UP and PAGE DOWN keys can be detected and trapped in a control by adding the following lines of Access Basic code to the KeyDown event for all the controls on a form where the PAGE UP and PAGE DOWN keys should be disabled:
   If KeyCode = KEY_PRIOR Or KeyCode = KEY_NEXT Then

      KeyCode = 0

   End If
				

NOTE: The constants for KeyCode are defined in the CONSTANT.TXT file, which is included with Microsoft Access. To use these constants in your code, you must either declare them yourself or copy them from the CONSTANT.TXT file and paste them into the Declarations section of your module.

The following example demonstrates how to detect and trap the PAGE UP and PAGE DOWN keys in a control's KeyDown event.

CAUTION: Following the steps in this example 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.
1.Open the Customers form in Design view.
2.Create an event procedure with the following code for the KeyDown event for each control on the form:
      If KeyCode = KEY_PRIOR Or KeyCode = KEY_NEXT Then
         KeyCode = 0
      End If
						

NOTE: To create each event procedure, select a control, click the Build button to the right of the OnKeyDown property, and then select Code Builder.

For example, the event procedure code for the Customer ID field will look as follows:
      Sub Customer_ID_KeyDown (KeyCode As Integer, Shift As Integer)
         If KeyCode = KEY_PRIOR Or KeyCode = KEY_NEXT Then
            KeyCode = 0
         End If
      End Sub
						
3.Close the module and then switch the form to Form view.
NOTE: Microsoft Access for Windows 95 introduces the new KeyPreview property that enables you to easily trap and disable keys in the form level key events. If the KeyPreview property is set to True, the following code will disable the ESC, PAGE UP, PAGE DOWN keys for the entire form:
     Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
          Select Case KeyCode
               Case 27, 34, 33
               KeyCode = 0
          End Select
     End Sub
				

Back to the top

REFERENCES

For more information about disabling PAGE UP and PAGE DOWN in Microsoft Access 95 and 97, please see the following article in the Microsoft Knowledge Base:

132031 (http://support.microsoft.com/kb/132031/EN-US/) ACC: How to Disable PAGE UP and PAGE DOWN Keys in a Form (95/97)

For more information about Dialog forms, search for "OpenForm," and then "OpenForm Action" using the Microsoft Access Help menu.

For more information about the KeyDown event, search for "KeyDown," and then "KeyDown, KeyUp Events" using the Microsoft Access Help menu.

Back to the top


APPLIES TO
Microsoft Access 2.0 Standard Edition

Back to the top

Keywords: 
kbhowto kbusage KB114506

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.