Disable Page Up, Page Down or Scrolling

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
 
R

Ragnar Midtskogen

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
 
T

Tom Stoddard

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.
 

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