Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-10
4
Medium Priority
?
3,515 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

604 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