From: Rana on
I am doing a project on Access 2003. I have a long form and needs to scroll
up/down often, That I am doing with my mouse well and Scrollbar. But I want
to scroll up/down with my up/down arrow keys. I want to scroll 1 inche down
everytime I press my down arrow.

I understand I have to write a code onkey up/down properties. Can someone
help me to write the code, plz?

Thanks,
From: Jeanette Cunningham on
Here's some code from Allen Browne that does that.
Put the code in a standard module.
Call it like this:
Call ContinuousUpDown(Me, KeyCode), in the form's KeyDown event.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call ContinuousUpDown(Me, KeyCode)
End Sub

You need to set the form's Key preview property to yes.


'start code ---------------------
Public Sub ContinuousUpDown(frm As Form, KeyCode As Integer)
'Purpose: Respond to Up/Down in continuous form, by moving record,
' unless the active control's EnterKeyBehavior is on.
'Usage: Call ContinuousUpDown(Me, KeyCode)
On Error GoTo Err_Handler
Dim strform As String

strform = frm.Name

Select Case KeyCode
Case vbKeyUp
If ContinuousUpDownOk Then
'Save any edits
If frm.Dirty Then
RunCommand acCmdSaveRecord
End If
'Go previous: error if already there.
RunCommand acCmdRecordsGoToPrevious
KeyCode = 0 'Destroy the keystroke
End If


Case vbKeyDown
If ContinuousUpDownOk Then
'Save any edits
If frm.Dirty Then
frm.Dirty = False
End If
'Go to the next record, unless at a new record.
If Not frm.NewRecord Then
RunCommand acCmdRecordsGoToNext
End If
KeyCode = 0 'Destroy the keystroke
End If
End Select

Exit_Handler:

Exit Sub

Err_Handler:
Select Case Err.Number
Case 2046, 2101, 2113, 3022, 2465 'Already at first record, or save
'failed, or The value you entered isn't valid for this field.
KeyCode = 0
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
Resume Exit_Handler

End Sub

Private Function ContinuousUpDownOk() As Boolean
'Purpose: Suppress moving up/down a record in a continuous form if:
' - control is not in the Detail section, or
' - multi-line text box (vertical scrollbar, or
'EnterKeyBehavior true).
'Usage: Called by ContinuousUpDown.
On Error GoTo Err_Handler
Dim bDontDoIt As Boolean
Dim ctl As control

Set ctl = Screen.ActiveControl
If ctl.Section = acDetail Then
If TypeOf ctl Is TextBox Then
bDontDoIt = ((ctl.EnterKeyBehavior) Or (ctl.ScrollBars > 1))
End If
Else
bDontDoIt = True
End If

Exit_Handler:
ContinuousUpDownOk = Not bDontDoIt
Set ctl = Nothing

Exit Function

Err_Handler:
If Err.Number = 2474 Then 'There's no active control
Else
MsgBox Err.Number & " " & Err.Description
End If
Resume Exit_Handler

End Function
'end code---------------------


"Rana" <Rana(a)discussions.microsoft.com> wrote in message
news:67734FCB-7567-4A29-9ACD-017810384538(a)microsoft.com...
>I am doing a project on Access 2003. I have a long form and needs to scroll
> up/down often, That I am doing with my mouse well and Scrollbar. But I
> want
> to scroll up/down with my up/down arrow keys. I want to scroll 1 inche
> down
> everytime I press my down arrow.
>
> I understand I have to write a code onkey up/down properties. Can someone
> help me to write the code, plz?
>
> Thanks,