Solved

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

Posted on 2013-01-10
4
2,760 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
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
This was exactly what I requested.  Worked perfectly!
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
Disregard, misread the question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now