Results 1 to 4 of 4

Thread: Tabs

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    Tabs

    I have a form with 3 textboxes on i. txt1, txt2 and txt3. I would like to know if I fill the txt1 with 2 digits, what would be the code to have the cursor tab to the next textbox.

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: Tabs

    Code:
    
    Private Sub txt1_Change()
        If Len(txt1.Text) = 2 Then txt2.SetFocus
    End Sub
    
    
    Something like that?
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    Re: Tabs

    Thar worked. Thanks

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Tabs

    BUT.....if you were to start using arrays of textboxes, it could look like this:

    Code:
    Private Sub Txt1_Change(Index As Integer)
        If Index = Txt1.ubound Then Exit Sub
        If Len(Txt1(Index).Text) = 2 Then Txt1(Index + 1).SetFocus
    End Sub
    this checks to see how many textboxes named Txt1 in an array of them...and when it reaches that last one, it exits.

    EDIT...if you set the maxlength of your highest numbered textbox in the array to 2 (in the IDE), then you will have ALL textboxes with 2 values.
    BUT, if you go back to any of the other textboxes which already have two characters in them and type in something else, you will end up with one (or more) with more than 2 characters.
    Best to set the maxlength of ALL your txt1 textboxes to 2 in the IDE. They you won't have an issue. whether you use arrays or not
    Last edited by SamOscarBrown; Jan 4th, 2023 at 06:40 PM.
    Sam I am (as well as Confused at times).

Tags for this Thread

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