View Single Post
 
Old 08-14-2019, 05:44 AM
sts023 sts023 is offline Windows 7 64bit Office 2010
Novice
 
Join Date: Apr 2019
Location: God's Own County
Posts: 22
sts023 is on a distinguished road
Default Cursor control in a textbox

Hi.
Im using Word 2010.
I have two text boxes in a frame on a Userform.
Textbox 1 (tbxItemText) is for an item description, textbox 2 (tbxPrice) is for the price.
Im trying to allow the User to hit Tab when in the item descriptipon to go to the price.
The code below does that, but when focus moves to textbocx 2, the cursor is two character positions to the right of the price (which was previously set to 0.00 after the preceding item was entered and accepted - and I've checked that there are no trailing spaces when it is set).
So I have two questions
first: can anyone think of any reason why the cursor should be beyond the end of the value?
and
second: is it possible to control the cursor position when setting focus to a textbox?


Code:
Private Sub tbxItemText_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
'*
'** Tab or Enter means "Go to Price".
'*
  Select Case KeyCode
    Case vbKeyReturn, vbKeyTab    'Enter or Tab
      Me.tbxPrice.SetFocus
  End Select
End Sub
Reply With Quote