Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    413

    Unanswered: Tab to Control on Form

    I have a form where I wish to tab to the first control after the data has been entered and remain on the current record. Here is my code I am trying to use. It however tabs to a new record instead of the current one. There is NO sub-form.

    Private Sub Picture3_KeyDown(KeyCode As Integer, Shift As Integer)
    DoCmd.SetWarnings False

    If KeyCode = Asc(vbTab) Then
    Forms!frm_mainThai![ChinaID].SetFocus
    KeyCode = 0
    End If
    End Sub

  2. #2
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Open the property sheet of the form, goto the Other tab then set the Cycle to Current Record.

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Poppa Smurf has given you the solution for this task. I've always wondered why the 'Boys of Redmond' chose 'All Records' as the Default setting for this Property instead of 'Current Record; I've answered this very question dozens and dozens and dozens of times!

    But this aside, to make your life easier, when writing code in the Code Module of a Form, and referring to a Control on that Form, instead of using

    Forms!frm_mainThai![ChinaID].SetFocus

    simply use the shortcut method of

    Me![ChinaID].SetFocus

    It means the same thing to the Access Gnomes, and cuts out the possibility of misspelling the Form's name and popping an error.

    Also note that in VBA code, like this, you do not need to enclose a Control's name in Square Brackets unless the name contains a Space or inappropriate non-AlphaNumeric characters. The only allowable non-AlphaNumeric character is the Underline Character.

    Also note that I wrote "in VBA code." Outside of the Code Module, such as when referring to a Control in the Conditional Formatting window, or when referring to a Control in the Properties Pane, such as in the Control Source Property of a Control, you must always enclose Control Names in Square Brackets!

    The Access Gnomes are a fickle bunch of guys!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •