Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Text box selection

I have a form with a text box containing a date formatted as mm/dd/yyyy.
When the box gets focus, I want the mm/dd part to be selected for
replacement. So far, I have the following:

Private Sub TextBox1_Enter()
TextBox1.SelStart = 0
TextBox1.SelLength = 5
End Sub

Private Sub UserForm_initialize()
TextBox1.Value = "01/01/4000"
TextBox2.Value = "04/03/1999"
End Sub

When the form comes up, textbox1 has focus and 01/01 is highlighted. But
when I press <enter, <tab, or click on a text box to enter it, it seems
that '_Enter()' doesn't fire at that time.

How can I get the first 5 characters highlighted every time I enter the text
box?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Text box selection

Tim

Change the EnterFieldBehavior to 1 for the Textboxes and it should work.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Tim Coddington" wrote in message
...
I have a form with a text box containing a date formatted as mm/dd/yyyy.
When the box gets focus, I want the mm/dd part to be selected for
replacement. So far, I have the following:

Private Sub TextBox1_Enter()
TextBox1.SelStart = 0
TextBox1.SelLength = 5
End Sub

Private Sub UserForm_initialize()
TextBox1.Value = "01/01/4000"
TextBox2.Value = "04/03/1999"
End Sub

When the form comes up, textbox1 has focus and 01/01 is highlighted. But
when I press <enter, <tab, or click on a text box to enter it, it seems
that '_Enter()' doesn't fire at that time.

How can I get the first 5 characters highlighted every time I enter the

text
box?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Text box selection

Thanks. That helps alot except for when you click on the box to enter it.
Is there any way to make it work then also?
"Dick Kusleika" wrote in message
...
Tim

Change the EnterFieldBehavior to 1 for the Textboxes and it should work.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Tim Coddington" wrote in message
...
I have a form with a text box containing a date formatted as mm/dd/yyyy.
When the box gets focus, I want the mm/dd part to be selected for
replacement. So far, I have the following:

Private Sub TextBox1_Enter()
TextBox1.SelStart = 0
TextBox1.SelLength = 5
End Sub

Private Sub UserForm_initialize()
TextBox1.Value = "01/01/4000"
TextBox2.Value = "04/03/1999"
End Sub

When the form comes up, textbox1 has focus and 01/01 is highlighted. But
when I press <enter, <tab, or click on a text box to enter it, it seems
that '_Enter()' doesn't fire at that time.

How can I get the first 5 characters highlighted every time I enter the

text
box?







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Text box selection

Tim

You could use the MouseDown event also, but you'll need a way to limit that
to only when the textbox is first selected. I'm not sure if there are any
problems with this, but here's something you could try:

Dim bEntered As Boolean

Private Sub TextBox1_Change()
bEntered = False
End Sub

Private Sub TextBox1_Enter()
Me.TextBox1.SelStart = 0
Me.TextBox1.SelLength = 3
bEntered = True
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

If bEntered Then
Me.TextBox1.SelStart = 0
Me.TextBox1.SelLength = 3
bEntered = False
End If
End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Tim Coddington" wrote in message
...
Thanks. That helps alot except for when you click on the box to enter it.
Is there any way to make it work then also?
"Dick Kusleika" wrote in message
...
Tim

Change the EnterFieldBehavior to 1 for the Textboxes and it should work.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Tim Coddington" wrote in message
...
I have a form with a text box containing a date formatted as

mm/dd/yyyy.
When the box gets focus, I want the mm/dd part to be selected for
replacement. So far, I have the following:

Private Sub TextBox1_Enter()
TextBox1.SelStart = 0
TextBox1.SelLength = 5
End Sub

Private Sub UserForm_initialize()
TextBox1.Value = "01/01/4000"
TextBox2.Value = "04/03/1999"
End Sub

When the form comes up, textbox1 has focus and 01/01 is highlighted.

But
when I press <enter, <tab, or click on a text box to enter it, it

seems
that '_Enter()' doesn't fire at that time.

How can I get the first 5 characters highlighted every time I enter the

text
box?









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
How to determine the text selection? Eric Excel Discussion (Misc queries) 7 September 14th 09 02:45 PM
Text Alighnment Across Selection Minitman Excel Discussion (Misc queries) 3 July 18th 08 03:47 PM
Text selection will not turn off Zoeyteach Excel Discussion (Misc queries) 1 April 9th 08 07:44 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
losing text from text box when pasting selection to word rallyworker Excel Discussion (Misc queries) 0 April 13th 07 08:44 AM


All times are GMT +1. The time now is 07:51 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"