Solved

Access VBA Code to move focus when Tab Key or Enter Key is pressed.

Posted on 2013-01-10
4
3,188 Views
Last Modified: 2013-01-10
In Access 2010 I have a form with the following fields.
TimeStart  LunchStart  Lunchend  TimeEnd  PTO  Holiday

If a user presses the Tab Key after entering data in the TimeEnd field, I want the cursor to move to the PTO field.  If a user presses the Enter Key after entering data in the TimeEnd field, I want the cursor to move to the Next Record.

Can anyone help me with this?

Thanks in advance!
0
Comment
Question by:Senniger1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38764427
use this codes, first set the form's keyPreview property to Yes

Private Sub TimeEnd_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
     'MsgBox "Tab"
     me.PTO.setFocus
End If
If KeyCode = vbKeyReturn Then
     'MsgBox "Enter Key"
     docmd.gotorecord,, acnewrec
End If
End Sub
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38764431
You need to adjust the controls Tab Order.  Not precisely sure how to do it in A2010, but in 2007, you would open the form in design mode.  Then select the Arrange tab on the Ribbon and Select Tab Order.  Then adjust the sequence of the controls within the section.

If the current action when it reaches the last control on the form is to jump to the first control on the same record, the you will need to change the FORMs Cycle property (Other tab of the Properties dialog) from "Current Record" to "All REcords"
0
 

Author Closing Comment

by:Senniger1
ID: 38764459
This was exactly what I requested.  Worked perfectly!
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 38764565
Disregard, misread the question.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question