'Limit text input and goto next textbox
'Of course you can set this also with the properties MaxLenght and TabIndex
'but if thats not enough:
'make a new project with a form and 3 textboxen (index 0,1,2)
'in the textbox(0) you can put 10 characters
'in the textbox(1) you can put 20 characters
'in the textbox(2) you can put 30 characters
'because it's in the keypress_event you get alwaus one character more
'in the CountCharacter you can chech on other Ascii-codes as
well
Option Explicit
Dim MaxCharacters as
Integer
Dim intCharacters as
Integer
Dim intTxtBox as
Integer
Private sub
Text1_GotFocus(Index as
Integer)
intCharacters = 0
select
case
Index
case
0
MaxCharacters = 9
intTxtBox = 1
case
1
MaxCharacters = 19
intTxtBox = 2
case
2
MaxCharacters = 29
intTxtBox = 0
end
Select
End Sub
Private sub
Text1_KeyPress(Index as
Integer, KeyAscii as
Integer)
CountCharacters (KeyAscii)
End Sub
Function CountCharacters(source)
'put the next line in the Textbox_KeyPress event
'CountCharacters(KeyAscii)
'backspace =8
If source <> 8 Then
'count characters
intCharacters = intCharacters + 1
'if there are more
than you want
If intCharacters > MaxCharacters Then
'goto next textbox
Text1(intTxtBox).SetFocus
Exit Function
end
If
Else
intCharacters = intCharacters - 1
end
If
CountCharacters = intCharacters
End Function
Return