Up Arrow Key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mclueless
    New Member
    • Jan 2008
    • 56

    Up Arrow Key

    I am using VB6 and Access. i have several text boxes arranged on a form. what is want is that when the focus is in a certain text box and the user presses the up arrow key, the focus goes to the text box before it. How can this be done??? Is there any way in which i can connect all textboxes like a linked list and shift the focus to previous text box on up arrow key press???? or any other way to achieve the same???
  • daniel aristidou
    Contributor
    • Aug 2007
    • 494

    #2
    Originally posted by mclueless
    I am using VB6 and Access. i have several text boxes arranged on a form. what is want is that when the focus is in a certain text box and the user presses the up arrow key, the focus goes to the text box before it. How can this be done??? Is there any way in which i can connect all textboxes like a linked list and shift the focus to previous text box on up arrow key press???? or any other way to achieve the same???
    You can use tab to change which textbox has focus.....

    Comment

    • mclueless
      New Member
      • Jan 2008
      • 56

      #3
      Originally posted by daniel aristidou
      You can use tab to change which textbox has focus.....

      But tab helps the focus to shift on a control with a higher tabindex property. what if i want to go back to some textbox where i already have been but want to go again for some modifications. What we normally do is take the mouse pointer to that text box and click but i want to allow this using keyboard

      Comment

      • Dawoodoz
        New Member
        • Oct 2006
        • 14

        #4
        This works for textbox Text1(0 to X)

        Code:
        Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
            Static Choose As Integer
            If KeyCode = vbKeyDown Then
                Choose = Index + 1
                If Choose >= Text1.Count Then Choose = 0
                Text1(Choose).SetFocus
            ElseIf KeyCode = vbKeyUp Then
                Choose = Index - 1
                If Choose < 0 Then Choose = Text1.Count - 1
                Text1(Choose).SetFocus
            End If
        End Sub

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Nice one Dawoodoz. I suppose you could also try simulating a Tab or BackTab keypress, but your technique is probably cleaner and more reliable.

          One thing - I hope these are single-line textboxes, or you may confuse the user.

          Another point - mclueless, have you considered using some type of grid control instead of textboxes?

          Comment

          • 9815402440
            New Member
            • Oct 2007
            • 180

            #6
            hi
            add following code to keydown event of every text box (if you are not using index array)

            [CODE=vb]Private Sub Text1_KeyDown(K eyCode As Integer, Shift As Integer)
            If KeyCode = vbKeyDown Then
            SendKeys "{TAB}"
            ElseIf KeyCode = vbKeyUp Then
            SendKeys "+({TAB})"
            End If
            End Sub[/CODE]


            regards
            manpreet singh dhillon hoshiarpur
            Last edited by Killer42; Feb 7 '08, 09:27 PM. Reason: Added CODE=vb tag

            Comment

            Working...