If the form is in Datasheet view, the down arrow moves down to the next
record. If the form is in Continuous for Form view, it does not.
To change that:
1. Paste the code below into a standard module, and save.
2. Set the Key Preview property of your form to Yes.
3. Set the On Key Down property to
[Event Procedure]
Click the Build button (...) beside this, and enter:
Call ContinuousUpDown(Me, KeyCode)
The code responds to the Up and Down arrows, but only if the active control
is in the Detail section of the form, and the control is not a multi-line
one.
--------------------code begins------------------------
Public Sub ContinuousUpDown(frm As Form, KeyCode As Integer)
On Error GoTo Err_ContinuousUpDown
'Purpose: Respond to Up/Down in continuous form, by moving record,
' unless the active control's EnterKeyBehavior is on.
'Usage: Call ContinuousUpDown(Me, KeyCode)
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_ContinuousUpDown:
Exit Sub
Err_ContinuousUpDown:
Select Case Err.Number
Case 2046, 2101, 2113 'Already at first record, or save failed, or
The value you entered isn't valid for this field.
KeyCode = 0
Case Else
MsgBox "Error " & Err.Number & " - " & Err.Description
End Select
Resume Exit_ContinuousUpDown
End Sub
Private Function ContinuousUpDownOk() As Boolean
On Error GoTo Err_ContinuousUpDownOk
'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.
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_ContinuousUpDownOk:
ContinuousUpDownOk = Not bDontDoIt
Set ctl = Nothing
Exit Function
Err_ContinuousUpDownOk:
If Err.Number <> 2474 Then 'There's no active control
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_ContinuousUpDownOk
End Function
--------------------code ends------------------------