Preventing PageUp/PageDown navigation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On forms where you have no scroll bars or navigation available to the user
and you want to restrict them to seeing only one record, how do you prevent
PageUp and PageDown keys from moving to previous and next records (assuming
also that the form's Cycle property is set to Current Record, which prevents
Tab from doing this)?
 
ctdak said:
On forms where you have no scroll bars or navigation available to the user
and you want to restrict them to seeing only one record, how do you prevent
PageUp and PageDown keys from moving to previous and next records (assuming
also that the form's Cycle property is set to Current Record, which prevents
Tab from doing this)?

You can trap for those keystrokes and cancel them, but what is better for lots
of other reasons is to show them the one record by using a filter or query that
*has no other records* rather than by navigating to it. Then the form has no
other records to show them in the first place.

A form with multiple records in its recordset has numerous ways that the user
can use to change records. If you trap for pageup and pagedown you will also
have to remove access to any menu or toolbar that would allow them to remove or
apply a filter. You would also have to remove access to Edit - Go To Record on
the main menu. A single record recordset that is selecting at the query level
(rather than a filter) has none of these issues and comes with the bonus of
performing much better as well since it never loads more than one record.

Cancelling the Page keys would involve setting the form's KeyPreview property to
True and then putting the following code in the form's KeyDown event

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyPageUp _
Or KeyCode = vbKeyPageDown Then KeyCode = 0

End Sub
 
Rick,

Thanks for the great input. Your advise sounds good to me. The problem I
am still having with one form is a form for a table that is not meant to have
more than one record. The user can hit PageDown and get to NewRecord, then
add a new record. This is what I want to prevent in this case. (The form
cannot be opened in Read-only mode.) How can I prevent the user from getting
to NewRecord?

ctdak
 
ctdak said:
Rick,

Thanks for the great input. Your advise sounds good to me. The problem I
am still having with one form is a form for a table that is not meant to have
more than one record. The user can hit PageDown and get to NewRecord, then
add a new record. This is what I want to prevent in this case. (The form
cannot be opened in Read-only mode.) How can I prevent the user from getting
to NewRecord?

Set AllowAdditions property of the form to No.
 
I wish this property would work as billed. I've never yet been successful at
setting any form's AllowAdditions property to No and have it prevent the user
from adding records! I tried this for the form in question and the user can
still go to NewRecord and add new records. Why is this? Any other ideas for
preventing the user from going to NewRecord?

ctdak
 
ctdak said:
I wish this property would work as billed. I've never yet been successful at
setting any form's AllowAdditions property to No and have it prevent the user
from adding records! I tried this for the form in question and the user can
still go to NewRecord and add new records. Why is this? Any other ideas for
preventing the user from going to NewRecord?

I have never had that problem. When AllowAdditions is set to No you should
see that the "go-to-new" button [>*] becomes disabled and any attempt to
move to a new record with other means is denied. Perhaps this is a bug in
the newer versions, but I don't recall seeing it mentioned in these forums
before.
 
AllowAdditions has always worked as documented for me. I cannot reproduce
the behaviour you describe.

That said, the following code will disable PageUp and PageDown and other
keystrokes that would cause record navigation. You'll need to also set the
form's Key Preview property to Yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyPageUp, vbKeyPageDown
KeyCode = 0
Case vbKeyHome, vbKeyEnd, vbKeyUp, vbKeyDown
If Shift And acCtrlMask Then
KeyCode = 0
End If
Case Else
'Do nothing.
End Select

End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Thanks for the code Brendan. I haven't used key trapping code before so this
helps. I will use it. As far as the problem I have with AllowAdditions not
working, I'll post a new thread and see if anyone else has the same problem.

ctdak
 
Back
Top