?
Solved

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

Posted on 2013-01-10
4
Medium Priority
?
3,354 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 2000 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
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
ID: 38764565
Disregard, misread the question.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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