Used to automatically tab to the next filed when a text box gets filled.
- Syntax
-
AutoTab
Call AutoTab
Remarks
This instruction is specifically designed for the Change event
of text boxes with a MaxLength property set greater than zero.
Example
Sub Text1_Change ()
Call AutoTab
End Sub
Source
Sub AutoTab()
Dim Text1 As Control
Dim Text As String
Dim Length As Integer
Dim MaxLen As Integer
On Error GoTo AutoTabTrap
Set Text1 = Screen.ActiveControl
Text = Text1.Text
Length = Len(Text)
MaxLen = Text1.MaxLength
If Length > MaxLen Then
'User pasted text longer than the max.
'This causes another change event so we'll be back.
Text1.Text = Left$(Text, MaxLen)
ElseIf Length = MaxLen And Text1.SelStart = MaxLen Then
SendKeys "{TAB}"
End If
AutoTabTrap:
Exit Sub
End Sub
|