ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SetFocus Problem (https://www.excelbanter.com/excel-programming/288430-setfocus-problem.html)

Todd Huttenstine[_2_]

SetFocus Problem
 
My original question was...What is the code to enter lets
say TextBox6. When I say this, I want the cursor to enter
that textbox.

Robin Hammond said to use setfocus

textbox6.setfocus

When I do this it does not work. The way I did it was
entering a value in textbox6 and clicking in another
textbox, if a certain condition is met a msgbox pops up
telling the user invalid value and then the next line is
textbox6.setfocus to bring the cursor back in that
textbox, but instead, the cursor goes to the textbox I
clicked.

How do I fix this?

Thank you

Todd Huttenstine

Bob Phillips[_6_]

SetFocus Problem
 
Todd,

This works for me

With TextBox6
.SetFocus
.SelStart 1
.SelLength = Len(.Text)
Cancel = True
End With

I use this code in the Textbox Exit event, as this has the option to cancel
an exit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
My original question was...What is the code to enter lets
say TextBox6. When I say this, I want the cursor to enter
that textbox.

Robin Hammond said to use setfocus

textbox6.setfocus

When I do this it does not work. The way I did it was
entering a value in textbox6 and clicking in another
textbox, if a certain condition is met a msgbox pops up
telling the user invalid value and then the next line is
textbox6.setfocus to bring the cursor back in that
textbox, but instead, the cursor goes to the textbox I
clicked.

How do I fix this?

Thank you

Todd Huttenstine




Todd Htutenstine

SetFocus Problem
 
Thank you that did it.


-----Original Message-----
Todd,

This works for me

With TextBox6
.SetFocus
.SelStart 1
.SelLength = Len(.Text)
Cancel = True
End With

I use this code in the Textbox Exit event, as this has

the option to cancel
an exit.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine"

wrote in message
...
My original question was...What is the code to enter

lets
say TextBox6. When I say this, I want the cursor to

enter
that textbox.

Robin Hammond said to use setfocus

textbox6.setfocus

When I do this it does not work. The way I did it was
entering a value in textbox6 and clicking in another
textbox, if a certain condition is met a msgbox pops up
telling the user invalid value and then the next line is
textbox6.setfocus to bring the cursor back in that
textbox, but instead, the cursor goes to the textbox I
clicked.

How do I fix this?

Thank you

Todd Huttenstine



.



All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com