I have a form in Access 2003 that should only be working with a single record. I can set the Cycle
property to Current Record
, but the form still jumps to the next record when I press Enter. My first thought was a KeyPreview
property, but I'm not seeing one. My other thought is maybe the KeyPress
or KeyUp
event, but I thought I'd ask in case of unintended consequences. Any ideas?
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.
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
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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With