Results 1 to 8 of 8

Thread: Tab index Problem

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Tab index Problem

    Hi,
    I have 25 text boxes in my form. While design i have assigned some tabindex.But while checking the entries in the text boxes i want to move the focus to the other box irrespective of the tab index. Is it possible..

    Dana

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Tab index Problem

    Use the SetFocus method of the control.

    Text4.SetFocus

    An error will occur if the control is not Visible or not Enabled so check before calling its SetFocus method

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Tab index Problem

    it is not working.The control not moving even if setfocus.i have written this in validate event of text box

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Tab index Problem

    Post your code.

  5. #5

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Tab index Problem

    Quote Originally Posted by danasegarane
    Hi,
    I have 25 text boxes in my form. While design i have assigned some tabindex.But while checking the entries in the text boxes i want to move the focus to the other box irrespective of the tab index. Is it possible..

    Dana
    you could assign alt-keys to the textboxes and then use the comination you need

  7. #7
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Tab index Problem

    Quote Originally Posted by danasegarane
    it is not working.The control not moving even if setfocus.i have written this in validate event of text box
    It can't be done in validate event, do it in LostFocus event.

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Tab index Problem

    it is not working.The control not moving even if setfocus.i have written this in validate event of text box
    It appears you cannot use SetFocus in the Validate event. Keep your "validation" code in the Validate event but use the LostFocus to decide which control to move to next.

    Example. 4 TextBoxes on a form. TabOrder is Text1, Text2, Text3, Text4. Change Text1 to a 3 or 4 and hit Tab

    VB Code:
    1. Private Sub Text1_Validate(Cancel As Boolean)
    2.     If Not IsNumeric(Text1.Text) Then
    3.         MsgBox "Invalid Data"
    4.         Cancel = True
    5.     End If
    6. End Sub
    7.  
    8. Private Sub Text1_LostFocus()
    9.     Select Case Text1.Text
    10.         Case "3"
    11.             Text3.SetFocus
    12.         Case "4"
    13.             Text4.SetFocus
    14.         Case Else
    15.             'anything else and focus is set to Text2
    16.             'which is the next control in the TabOrder
    17.     End Select
    18. End Sub
    19.  
    20. Private Sub Form_Load()
    21.     Text1.Text = "1"
    22.     Text1.MaxLength = 1
    23. End Sub

    This code did not work, Text2 was always the next control to get Focus.
    VB Code:
    1. Private Sub Text1_Validate(Cancel As Boolean)
    2.     If Not IsNumeric(Text1.Text) Then
    3.         MsgBox "Invalid Data"
    4.         Cancel = True
    5.     Else
    6.       Select Case Text1.Text
    7.         Case "3"
    8.             Text3.SetFocus
    9.         Case "4"
    10.             Text4.SetFocus
    11.         Case Else
    12.             'anything else and focus is set to Text2
    13.             'which is the next control in the TabOrder
    14.       End Select
    15.     End If
    16. End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width