Disable PageUp and PageDown Keys

H

Henry

when doing a: DoCmd.GoToRecord , , acNewRec

and pressing the page up/down buttons the form jumps to the next record.

any idea on how to force a form to stay within the current data record ?

henry
 
A

Allen Browne

You can set the form's KeyPreview to Yes, and then use the KeyDown event to
trap the PageUp/PageDown keystrokes and destroy them by settting KeyCode to
zero.

The more important question is what you are trying to do here. If you are
trying to ensure that the record is filled out completely before the user
moves to another record, use the BeforeUpdate event of the form to perform
the record validation. Access fires that event regardless of why the record
is being saved, e.g. the user scrolled the mouse, pressed Shift+Enter,
closed the form, chose Save Record from the Records menu, closed Access,
and so on.

This example shows how to use the event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.Surname) Then
Cancel = True
MsgBox "Enter a surname."
End If
End Sub
 
T

Tim Ferguson

any idea on how to force a form to stay within the current data record ?

If I really want the user to work with one record at a time, I only give
them one in the Form.Recordsource:

SELECT * FROM SomeTable WHERE PKValue=1038

The Cycle property can also limit the user to one page or record or not,
but I don't know how that affects the PgUp/ PgDn keys.

Hope that helps


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top