Page Up and Down Keys

G

Guest

I have a form with multiple pages divided with page breaks. I'd like to
disable the page up and down keys from maneuvering within a record to the
next or previous page but have them able to go to the next or previous
records. So if I hit page down, it takes me to the next record and not the
next page in the record I'm in.

Any suggestions?

Thanks

Kevin
 
A

AccessVandal via AccessMonster.com

Hi Kevin,

You can use the Form's event like "OnKeyDown" or "OnKeyPress".
and set the Form's Property "KeyPreview" to Yes.

The KeyCode is 33 and 34 for PageUp and PageDown in the KeyDown event.

Use the keyDown event to go to next/previous records
if the keydown event is triggered.

Something like...

If KeyDown = 33 then
DoCmd.GoToRecord , , acPrevious
ElseIf KeyDown = 34 then
DoCmd.GoToRecord , , acNext
End If

or

Select Case KeyCode
Case 33
DoCmd.GoToRecord , , acPrevious
Case 34
DoCmd.GoToRecord , , acNext
End Select
 
A

AccessVandal via AccessMonster.com

Note the error, Keycode not KeyDown.

If KeyCode = 33 then
DoCmd.GoToRecord , , acPrevious
ElseIf KeyCode = 34 then
DoCmd.GoToRecord , , acNext
End If
 
G

Guest

This works great! One issue though. If I'm on the first record and I press
the page up key I get a run time error box telling me I can't go to the
specified record. Same thing if I'm on a new record and hit the page down
key.

What code can I add to prevent this from happening?

Thanks,

Kevin
 
A

AccessVandal via AccessMonster.com

Hi Kevin,

Try to use the error handling to trap the error.Like....

On Error GoTo err_handler
Select Case KeyCode
Case 33
DoCmd.GoToRecord , , acPrevious
Case 34
DoCmd.GoToRecord , , acNext
End Select

err_handler_Exit:
Exit Sub
err_handler:
If Err.Number = 2105 Then 'trap the error code here
KeyCode = 0
Resume err_handler_Exit
Else
MsgBox Err.Number & "-" & Err.Description
End If
 

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