Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default SetFocus in user form

I am creating a user form with a text box that starts with the number
0. I've got the userform_activate to set textbox1.setfocus so that
the cursor is in the text box. However, I find that the cursor is
blinking at the end of the 0, so that the user has to tap to the front
and then go forward to highlight the 0 in order to put in a new
number. How can I set it so that the 0 is highlighted right away, and
the user can input the right number over the 0 immediately?

Many thanks for advice!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default SetFocus in user form

Try this one John

Private Sub UserForm_Activate()
With Me.TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"John Tjia" wrote in message om...
I am creating a user form with a text box that starts with the number
0. I've got the userform_activate to set textbox1.setfocus so that
the cursor is in the text box. However, I find that the cursor is
blinking at the end of the 0, so that the user has to tap to the front
and then go forward to highlight the 0 in order to put in a new
number. How can I set it so that the 0 is highlighted right away, and
the user can input the right number over the 0 immediately?

Many thanks for advice!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default SetFocus in user form

Private Sub TextBox1_Enter()
With TextBox1
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"John Tjia" wrote in message
om...
I am creating a user form with a text box that starts with the number
0. I've got the userform_activate to set textbox1.setfocus so that
the cursor is in the text box. However, I find that the cursor is
blinking at the end of the 0, so that the user has to tap to the front
and then go forward to highlight the 0 in order to put in a new
number. How can I set it so that the 0 is highlighted right away, and
the user can input the right number over the 0 immediately?

Many thanks for advice!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default SetFocus in user form

John,

I'm not sure about the highlighting aspect of your question, but here's what
you can do to shift the insertion point to the left of the zero:

With UserForm1.TextBox1
.Text = "0"
.SetFocus
.SendKeys{LEFT}
End With

-- Dennis Eisen
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default SetFocus in user form

Thanks to all! The .SelStart = 0, .SelLength = Len(.Text) code is
great.

Dennis, I tried your code, but VBA didn't accept the .SendKeys{LEFT}.
I saw something once that was the equivalent of a Tab command in the
userform, i.e., set the focus on the next item in the tab order, and
then do a Shift+Tab equivalent to back up. Thanks for the reply.


(DennisE) wrote in message ...
John,

I'm not sure about the highlighting aspect of your question, but here's what
you can do to shift the insertion point to the left of the zero:

With UserForm1.TextBox1
.Text = "0"
.SetFocus
.SendKeys{LEFT}
End With

-- Dennis Eisen



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default SetFocus in user form

John,

I was (incorrectly) trying to recall from
memory the form of the SendKeys that would do the shifting. The correct form
of the instruction is as follows, and will
result in "AB|C" showing up in the
TextBox, rather than "ABC|".

Sub ShiftLeft( )
UserForm1.TextBox1.Text = "ABC"
Application.SendKeys ("{LEFT}")
UserForm1.Show
End Sub

And to be precise about the .SelLength and .SelStart properties, you'd want to
use .SelStart = Len(.Text) - 1 and
..SelLength = 1 to get you to shift the
insertion point one character to the left
and highlight the rightmost character.

-- Dennis Eisen
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SetFocus in user form

Dennis later said in a separate thread:

I've been wrestling with this one for days, and I just can't
seem to pull it off. What I'd like to do when a certain TextBox
on a UserForm takes the focus is to have the insertion point
automatically move one space to the left. So, for example,
if the TextBox contains ""ABC" upon taking the focus what
I want to see is "AB|C"; I've been trying to do this by using
Application.SendKeys "{LEFT}" in some manner but to no
avail. I can obviously do it manually by pressing the left arrow
key, but I want to do it in VBA so as to remind the user of how
the data entry appearing in that particular TextBox is to be
modified. Anyone have any ideas on how to do this?

-- Dennis Eisen

so even he doesn't appear to be still enamored with his suggeste solution.

--
Regards,
Tom Ogilvy

"John Tjia" wrote in message
m...
Thanks to all! The .SelStart = 0, .SelLength = Len(.Text) code is
great.

Dennis, I tried your code, but VBA didn't accept the .SendKeys{LEFT}.
I saw something once that was the equivalent of a Tab command in the
userform, i.e., set the focus on the next item in the tab order, and
then do a Shift+Tab equivalent to back up. Thanks for the reply.


(DennisE) wrote in message

...
John,

I'm not sure about the highlighting aspect of your question, but here's

what
you can do to shift the insertion point to the left of the zero:

With UserForm1.TextBox1
.Text = "0"
.SetFocus
.SendKeys{LEFT}
End With

-- Dennis Eisen



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
user form Ruth Excel Discussion (Misc queries) 3 October 30th 08 12:51 PM
user form Jase Excel Discussion (Misc queries) 1 March 25th 08 09:51 PM
How do I fill a cell in a user form from a selection on same form? Terry Tipsy Excel Discussion (Misc queries) 4 June 11th 07 02:59 PM
User form Mike Rogers New Users to Excel 7 December 16th 05 05:07 PM
I am looking to see if anybody has an equivalant user form to Outlooks CONTACT form BruceJ[_2_] Excel Programming 2 October 15th 03 05:28 PM


All times are GMT +1. The time now is 08:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"