|
-
Jan 4th, 2023, 03:47 PM
#1
Thread Starter
Junior Member
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.
-
Jan 4th, 2023, 04:25 PM
#2
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.
-
Jan 4th, 2023, 04:53 PM
#3
Thread Starter
Junior Member
-
Jan 4th, 2023, 06:29 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|