Re: Select all when control gets focus



you're welcome, Bill ;) happy to help


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*



BFish via AccessMonster.com wrote:
Thanks Crystal,

You have helped in a big way! See below.

Short of
SendKeys "{F2}"
... for selecting the whole phone number when you click in ... how about something like this:

'~~~~~~~~~~~~~~
Private Sub Phone_Click()
Me.Phone.SelStart = 1
Me.Phone.SelLength = 14
End Sub
'~~~~~~~~~~~~~~~

since you are not storing the symbols, I hard-coded numbers in -- since the length in the control is > len(fieldname) ... you will need to test what is there and make appropriate adjustments...

this is annoying in that each time they click, it will keep selecting everything (so they won't be able to click a digit and change it -- testing to see if they have left the field since their last click (global variable) might be a good idea - set on GotFocus, clear on LostFocus


Private Sub Phone_Click()
Me.Phone.SelStart = 1
Me.Phone.SelLength = 14
End Sub


I have tried that code on click event. A combination of the control being a
combobox and click event only updating after an update (research from this
board) the it will select the text but by default will the Microsoft
Programmed click event will leave the cursor at the click point and that
being the final move.

another alternative is to make a command button for them to click on

caption --> Select Phone
click [Event Procedure] --> me.phone.setfocus


This code on a command jarred my memory from probably a year ago on a post I
had stored in the grey matter.

After searching again I finally found some code from Marshall Barton from
back in 2004.

"The only way I can think of to overcome the standard mouse
processing is to place a transparent command button on top
of the combo box. Then use the buttons GotFocus event to
swith the focus to the combo box:

Me.MyCombobox.SetFocus
Me.MyCombobox.SelStart = 0
Me.MyCombobox.SelLength = Len(Me.MyCombobox.Text)"

Works absolutely great and also overides the issue of not being able to edit
an entry due to focus moving to the intended control after the first click,
2nd click will place cursor at the click point.

Thanks to this board, People like you Crystal and Marshall Barton and others
posting back solutions.
This site has been a great reference for many questions that many times I
have not had to post but just perform a search on a subject.

GREAT SITE, GREAT PEOPLE!

Thanks again,

Bill Fischer

.