Forms:Continous Form, Make Behave Like Spreadsheet

Friday, March 21, 2003 10:23:00
home

Notice with continuous forms, typically the arrow-key behavior is nothing like that of a regular spreadsheet or datasheet. When you press the down-arrow key, you jump to the next field rather than to the next record as you would think. Same thing with the up-arrow key. There is a way around it, though, in this code derived from the Access 2000 Developer's Handbook, Volume 1, Chapter 8.

  1. With your form open in "Design" view, set the properties sheet "Event.....Key Preview" equal to "Yes"
  2. Enter the following code in the form's On Key Down" Event Procedure
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
     On Error GoTo HandleErrors
    Select Case KeyCode
        Case vbKeyDown
            DoCmd.GoToRecord Record:=acNext
            KeyCode = 0
        Case vbKeyUp
            DoCmd.GoToRecord Record:=acPrevious
            KeyCode = 0
        Case Else
            ' Do nothing at all!
    End Select

ExitHere:
    Exit Sub
    
HandleErrors:
    Select Case Err.Number
        Case 2105
            KeyCode = 0
        Case Else
            MsgBox "Error: " & Err.description & _
             " (" & Err.Number & ")"
    End Select
    Resume ExitHere
End Sub

  1. Save and close your form