+ Reply to Thread
Results 1 to 3 of 3

Keydown and SelStart problem

  1. #1
    jase
    Guest

    Keydown and SelStart problem

    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


  2. #2
    Jim Rech
    Guest

    Re: Keydown and SelStart problem

    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
    "jase" <[email protected]> wrote in message
    news:[email protected]...
    | 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
    |



  3. #3
    jase
    Guest

    Re: Keydown and SelStart problem

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

    Jason


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1