Change the pgup and pgdn key behavior.

RFigaro

Registered User.
Local time
Today, 13:56
Joined
Aug 5, 2012
Messages
18
How can I make the pgup and pgdn keys behave like an excel spreadsheet where the focus stays in the same field that the pgup or pgdn keys were pressed? Now when I press the page down or up in my subform the focus shifts to the first tab stop of the new paged down or up record. Any code to help me achieve this would be highly appreciated.
Thank you,
 
First set the form's KeyPreview property to YES.

Next, paste this code into the form's module
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo err_handler
    Select Case KeyCode
    Case 33
        KeyCode = 0
        Me.Recordset.MovePrevious
    Case 34
        KeyCode = 0
        Me.Recordset.MoveNext
    End Select
    
exitkeydown:
    Exit Sub
err_handler:
    If Err.Number <> 3021 Then
        MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
        Resume Next
        Resume
    End If
End Sub
 
Last edited:
Added an error handler in the code above.
 
Thanks for the rapid reply Bob I really appreciate it. I happened to be reading one of your other great posts just now.
That code is great I currently use an almost identical code for my up and down arrows (I had to add a check for last record). I need to do exactly what your code does except move down 20-25 records mimicking the amount up or down that pgup or down would take me.
 
(I had to add a check for last record).
Not if you use the error handler like I have on the code I posted. It will just ignore it basically but you could add a message box to notify the user.
 
The code Bob posted works well but only moves up or down one record. Is there any way to mimic a full page up or down function in a continuous view form? I tried using move + a number of records but this doesn’t work like the real page up and down. When my form is in datasheet view pgup and pgdn works fine. Is there a way to change the tab stop order when the pgdn key is pressed to keep the cursor in the current field then change it back after the pgdn move? Any help on this will be highly appreciated.
Alternatively, I am using Allen Browne’s tip on how to enter text into a calculated field using hidden unbound text boxes and I need to be in continuous view for this to work. If there is a way to get this to work in datasheet view that would be a great solution too.
 
Sorry, been too busy to post the last few days. Hmm, yeah, I see what you mean but I'm not sure exactly how to do it. You might take a look at your subform and figure out how many records fit. Then just have it do
Code:
Dim i As Integer
Const iRec As Integer = 6 ' for example
 
For i = 1 to iRec
   Me.Recordset.MoveNext
Next
 
Thanks Bob,
I was really hoping to have the pgup and pgdn work like it does in datasheet view as my users stretch the form to fit their screen. In datasheet view it appears to calculate that change in size of the form. I am going to try to convert the form to datasheet view and write code get it the functionality I have currently have with my stacked text boxes that calculate a change in unit price when the user updates the total price.
 

Users who are viewing this thread

Back
Top Bottom