Keydown and SelStart problem

J

jase

If you create a Textbox TextBox1 and give it text of "abcdefg" in the
properties window then why doesn't the second event procedure below
select "de" when you press the right arrow on the keyboard when the
textbos has got the focus ??!

Any help greatly appreciated
Jason.


Private Sub TextBox1_GotFocus()
TextBox1.SelStart = 0
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Select Case KeyCode
Case vbKeyRight
With TextBox1
.SelStart = 3
.SelLength = 2
End With
Case Else
End Select
End Sub
 
J

Jim Rech

You're letting the right arrow through. You have to kill it:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
Select Case KeyCode
Case vbKeyRight
With TextBox1
.SelStart = 3
.SelLength = 2
End With
KeyCode = 0 ''<<<<<
End Select
End Sub


--
Jim
| If you create a Textbox TextBox1 and give it text of "abcdefg" in the
| properties window then why doesn't the second event procedure below
| select "de" when you press the right arrow on the keyboard when the
| textbos has got the focus ??!
|
| Any help greatly appreciated
| Jason.
|
|
| Private Sub TextBox1_GotFocus()
| TextBox1.SelStart = 0
| End Sub
|
| Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
| ByVal Shift As Integer)
| Select Case KeyCode
| Case vbKeyRight
| With TextBox1
| .SelStart = 3
| .SelLength = 2
| End With
| Case Else
| End Select
| End Sub
|
 
J

jase

Cheers Jim
Works beautifully.
Have you got any examploes to help me understand how this has worked?

Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top