投稿日 | : 2004/02/04(Wed) 11:53 |
投稿者 | : いちゆ |
Eメール | : |
URL | : |
タイトル | : Re: 入力文字数でのフォーカス制御 |
じゃ、これは?
Const TextBox1_MaxLength = 10
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim i As Long
Dim st As String
Select Case KeyAscii
Case vbKeyReturn
TextBox2.SetFocus
Case Else
TextBox1.SelLength = 0
st = TextBox1.Text
If Mid$(st, TextBox1.SelStart + 1, 1) <> "" Then
i = TextBox1.SelStart
Mid$(st, TextBox1.SelStart + 1, 1) = ChrW$(KeyAscii)
TextBox1.Text = st
TextBox1.SelStart = i + 1
KeyAscii = 0
End If
If Len(TextBox1.Text) >= TextBox1_MaxLength Then
KeyAscii = 0
TextBox1.Text = Left$(TextBox1.Text, TextBox1_MaxLength)
TextBox2.SetFocus
End If
End Select
End Sub