Microsoft Office Forums Cursor control in a textbox

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-14-2019, 05:44 AM
sts023 sts023 is offline Cursor control in a textbox Windows 7 64bit Cursor control in a textbox Office 2010
Novice
Cursor control in a textbox
 
Join Date: Apr 2019
Location: God's Own County
Posts: 21
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
  #2  
Old 08-14-2019, 08:41 AM
gmaxey gmaxey is offline Cursor control in a textbox Windows 10 Cursor control in a textbox Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 918
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

the tab is being applied to the txtPrice contorl.

Code:
Private Sub tbxItemText_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  Select Case KeyCode
    Case vbKeyReturn, vbKeyTab
      With tbxPrice
        .SetFocus
        .SelStart = 0
        .SelLength = 4
      End With
      KeyCode = 0
  End Select
End Sub

Private Sub UserForm_Initialize()
  tbxPrice.Text = "0.00"
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-14-2019, 09:08 AM
sts023 sts023 is offline Cursor control in a textbox Windows 7 64bit Cursor control in a textbox Office 2010
Novice
Cursor control in a textbox
 
Join Date: Apr 2019
Location: God's Own County
Posts: 21
sts023 is on a distinguished road
Thumbs up GM wins again!

Blindingly obvious when you think about it - the Tab key has still been pressed, and will therefore be processed somewhere!
I didn't know about the SelStart and SetLength options, so thanks again Greg, I'm just a teeny bit wiser now!
I should have gone to The Anchorage sooner, I'd forgotten what a great site it is...
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cursor control in a textbox How to control INPUT CURSOR location when clicking in Word after being in another app? Retko Word 1 04-11-2019 09:34 PM
Cursor control in a textbox Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Printing content of textbox Active X control donnashim Word 0 05-12-2015 02:48 AM
Textbox control autosize and mutliline kogi Word VBA 3 09-25-2014 06:15 AM
Cursor control in a textbox Display result in textbox based on the input of another textbox scarymovie Word VBA 5 05-16-2012 07:05 PM


All times are GMT -7. The time now is 12:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft