Prevent moving to next record when hitting Enter?

The Cycle property only affects the TAB key.

To control the behaviour of the Enter Key that's a global property.

Go to Tools/Options - Keyboard tab and on "Move After Enter" select "Next Field"

There are KeyPress and KeyDown events that you can use to trap the Enter key too but that's more work.


The moment keys like TAB, Alt, PgUP, PgDn, Enter are pressed at the end of adding the record (after the last field mostly), the database auto saves all the info you entered on the form and wipes out the fields so that you can enter the next value. So what happens is that the data is saved but the form looks empty.

3 things to do:

  1. Form Cycle Property set to Current Record.
  2. Form Key Preview Property set to Yes.
  3. Add following code to the KeyDown Event of the form:

    '33 - PgUp; 34 - PgDown; 9 - Tab; 18=Alt; 13=Enter
    
    Select Case KeyCode
    Case 33, 34, 18, 9, 13
    KeyCode = 0    
    Case Else
    'Debug.Print KeyCode, Shift
    End Select
    

    I found this while scouring the web and don't take credit/responsibility for the code but I don't know where I found it. Works for me!


This can also be done in vba.

Application.GetOption "Move After Enter" 'get current setting
Application.SetOption "Move After Enter", 0 'don't move
Application.SetOption "Move After Enter", 1 'Next Field
Application.SetOption "Move After Enter", 2 'Next Record

http://www.pcreview.co.uk/forums/enter-key-moving-next-field-t3454281.html

Tags:

Ms Access

Vba