tags:

views:

2114

answers:

3

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?

+3  A: 

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.

DJ
Funny, it never occured to my that my "user preference" was affecting my application. Fortunately, my users are probably not savvy enough to go digging through the options. This works for me. Thanks.
Michael Itzoe
Won't that affect the whole application. What if you just want to do that on just some forms, not all? Isn't "Next field" the default behavior too?
CodeSlave
You should probably have your app check the setting for this option, using GetOption and if it's not what you want, set it with GetOption. If you want to return the user's setup to it's original setting, you'll want to cache the original value and reset when the app closes.
David-W-Fenton
A: 

The Cycle property only works with the Tab key.

There are two options you could pursue.

You could trap the Enter key in KeyDown/KeyUp/KeyPressed
- OR -
You could filter the data source to the one record you want them editing, and disable adding new records through that form.

CodeSlave
A: 

You can add below code to your form 'BeforeUpdate' event. If use want to move to next record, it will ask user to save then close the form before they can move to another recorde.

  Private Sub Form_BeforeUpdate(Cancel As Integer)
    Select Case MsgBox("Save?", vbYesNo)
      Case vbYes
        DoCmd.Close
      Case vbNo
        Cancel = True
    End Select
  End Sub
Vinate
This code only fire if the record has been updated, so it's not really a solution to the original problem at all.
David-W-Fenton