Keyboard move after enter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Arturo Villar
    New Member
    • Oct 2011
    • 4

    Keyboard move after enter

    In a continuos form, ¿how can I get that the Enter on a field changes to the same field, next record, and not to the next field (moving vertically and not horizontally)?
    I found an example that changes the behaivor of the Enter Key to "Don't move":

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 13 Then
            KeyCode = 0
        End If
    End Sub
    But I need to move to the next record of the same field (move down). I tried to set KeyCode = vbKeyDown but also this key move to the next field (moves right). ¿What should I set the KeyCode?
    Last edited by NeoPa; Oct 4 '11, 11:50 AM. Reason: Added mandatory [CODE] tags for you
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Try looking at modifying the Tab Order as well as the Tab Stop property.

    The Tab stop will indicate whether focus will move to that control or not, when you press tab (and also when you press enter I believe).

    The tab order indicates the order in which the tab key moves around the form.

    You also need to look at the cycle property and see whether its set to "Current Record" or "All Records", this indicates when pressing Tab whether or not the cycling should move to the next record, when at the last control.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32666

      #3
      Try out :

      Code:
      'Form_KeyDown only runs if the form's .KeyPreview property is True.
      Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
          Dim intWrk As Integer
      
          If KeyCode = vbKeyReturn Then
              'No reliable way to determine if we're already on the last record.
              On Error Resume Next
              If Not Me.NewRecord Then Call DoCmd.GoToRecord(Record:=acNext)
              On Error GoTo 0
              KeyCode = 0
          End If
      End Sub
      I would advise handling the Shift value too if you want your code to work intuitively for the operator.

      Comment

      • Arturo Villar
        New Member
        • Oct 2011
        • 4

        #4
        @TheSmileyCoder : Thank you for your answer, but the problem is that I need this behavior with all the columns: Column #1: Rec #1, #2, #3, Then Column #2: Rec #1, #2, #3 and so on.
        _______________ _______________ _______________ ______
        @NeoPa: Thank you! That was exactly what I needed!

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32666

          #5
          Arturo, responding politely to all comments in your thread is a good way to get yourself a good reputation around here. Nice start :-)

          PS. I'm pleased that worked for you.

          Comment

          • Arturo Villar
            New Member
            • Oct 2011
            • 4

            #6
            NeoPa, Thank you again! You saved me many work hours!

            Comment

            • TheSmileyCoder
              Recognized Expert Moderator Top Contributor
              • Dec 2009
              • 2322

              #7
              Im pleased that NeoPa's solution worked for you. I was originally contemplating whether to include code similar to Neo's in my post but decided to start by keeping it simple. I sometimes have a tendency to "oversolve" and thus overcomplicate issues. :)

              Comment

              • Arturo Villar
                New Member
                • Oct 2011
                • 4

                #8
                TheSmileyCoder, Thank you for your interest.

                Comment

                Working...