Textboxes in UserForms

  • Thread starter Roderick O'Regan
  • Start date
R

Roderick O'Regan

I have a userform with five textboxes. When the form initializes it
"reads" text located between bookmarks and places the various textual
items into their respective textboxes.

Is there a way, please, to show the contents of the first textbox
highlighted rather than the cursor being at the end of the text?

Naturally, when I press TAB to go to the next field the text is
highlighted.

A typical example of what I want to achieve is when one goes to
Tools|Options|User Information in Word and the Name field contents are
highlighted automatically.

Regards

Roderick
 
D

Doug Robbins

Have you tried using SetFocus on the field?

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Roderick O'Regan

Thanks, Doug. Yes, I've tried it in the following way:
myfieldname.SetFocus but still with no luck - the cursor just goes to
the end of the words brought in from the bookmarked area.

Roderick
 
D

Doug Robbins

This appears to do it:

TextBox1.SelStart = 0
TextBox1.SelLength = Len(TextBox1.Text)
TextBox1.SetFocus


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Roderick O'Regan

It works! Thanks Doug.

When one reads what the code is saying it's blindingly obvious!

Regards

Roderick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top