In Microsoft Access how do you prevent the cursor from going to a new field after you hit enter?

J.R. Sitman
J.R. Sitman used Ask the Experts™
on
when entering data in a field that is for searching after you hit enter the cursor jumps to a different field.   I do I set it so it does not leave the search field?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lansing Nye-MaddenNetwork Administrator

Commented:
I don't have an environment set up right now that I could use to test this, so please keep that in mind, but can you utilize the event when the cursor leaves the box to place the focus back on the control that fired the event? (This may break your tab functionality and you would lose your ability to select another control)
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Go to menu Files, Settings, Client settings.
Move setting in the first option, Move cursor with Enter, from:

    Next field

to:

    Do not move

Click OK and relaunch.
Lansing Nye-MaddenNetwork Administrator

Commented:
Does this information get included in the database file or only with the particular Access Client that is accessing the database?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

J.R. SitmanIT Director

Author

Commented:
will that setting apply to all fields?   If so I do not want that.
Database Architect / Application Developer
Top Expert 2007
Commented:
In the AfterUpdate Event for that Text ... put this:
Me.YourTextBoxName.SetFocus
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
You can do something like this:

Private Sub YourTextBox_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyReturn Then
        KeyCode = 0

        ' Save form/record.
        If Me.Dirty = True Then
            Me.Dirty = False
        End If
        ' or call your search function. Use Text if textbox not updated, as Value is not updated.
        MySearchFunction Me!YourTextBox.Text
    End If

End Sub

Open in new window

J.R. SitmanIT Director

Author

Commented:
Sorry, Lansing, it does work.
J.R. SitmanIT Director

Author

Commented:
Thanks
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
You are welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial