Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setfocus with cursor at end of text 2

Status
Not open for further replies.

jimlee

Programmer
Jan 27, 2001
213
GB
Hello
I need to set the focus of my text box so that the cursor position is at the end of the text that is already there (ie at the point at which the user will next enter text).

any ideas appreciated

jimlee
 
Take a look at the SelStart property.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi jimlee,

It depends on which app and the sort of textbox and the method of gaining focus. Can you give a bit more detail, please?


Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi,
I am using Access97 and coding from the event window eg txtComments.setfocus

it sets the focus ok but all the text is highlighted, I just want the cursor at the end.

I will have a look at the selstart thing when i get chance, cheers


jimlee
 
Hi jimlee,

After the setfocus, you could use the horrible sendkeys ..

Code:
[blue]txtComments.setfocus
SendKeys "{F2}"[/blue]

Got a feeling there's a better way though!


Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi!

Don't think this is better, I think PHV's suggestion on using SelStart is probably the best/most efficient on single controls.

But, just for fun, one could play around with the options in Tools | Options, either thru the menu:
The Keyboard tab. In the "Behavior entering field, change from "Select entire field" to "Go to end of field".

Or programmatically:

[tt]application.setoption "behavior entering field", 2[/tt]

0 - Select entire field
1 - Goto start of field
2 - Goto end of field

BTW for Access questions, check out the access fora. You'll find some of them in the "Related Forums" box at right.

Roy-Vidar
 
worked a treat, thanks for the help

jimlee
 
Roy-Vidar

Thanks from me as well. I was trying to figure out the syntax for the [blue]SetOption[/blue]. I now have two icons on my form, which allows the user to change the behavior without giving the user access to the Access Options form.

Dalain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top