Disable Page Up, Page Down or Scrolling

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi All,

How can you disable going to a new record on a form when
you press the page up or page down keys or the scrolling
wheel on the mouse.

Thanks in advance.

Chris
 
Hi Chris,

I am not familiar with the scrolling wheel on the mouse, but the KeyUp and
KeyDown can be handled by setting the form's Key Preview to Yes, and add
this event proc for the KeyDown event:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If ((KeyCode = vbKeyPageDown) Or (KeyCode = vbKeyPageUp))then
KeyCode = 0
End If
End Sub

Setting the KeyCode to 0 tells Access to disregard the keystroke.
I suppose you already has set the form's Cycle property to Current Record?
Otherwise, user could use the Tab key to go from the last TabStop to go to a
new record.

Ragnar
 
Thanks! you just helped me realize why something was happening in an
application I just developed. It was the mouse wheel causing records to
update.

I was able to fix it by putting code in the beforeUpdate event of the form.
I want users to use a button to save the record and close the form so I
created a form level variable called fOkToSave as Boolean. I then put code
in the click event of the finish button that sets fOkToSave to true. In the
form's BeforeUpdate event I simply test for fOkToSave and if it's false I
cancel the event. This also works to prevent using the page keys.

This is a quick solution that I haven't had time to test thoroughly yet so
be careful using it. You might have many other things going on in your form
that I'm not aware of. Let me know if you find any better solutions.
 
Back
Top