Got Focus Select All

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to have all the text currently in a textBox be selected when it
receives focus so the user can enter or change data easily.

I've tried: [textName1].selectAll
And: Me.textName1.selectAll

selectAll isn't it....
how would I do this?
 
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)

The reason for the vbNullString is to ensure no problems if textName1
contains Null.
 
You may also add a Me.textName1.SelStart before, to ensure the cursor is at
the start of the string, before selection; so:

Me.textName1.SelStart = 0
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)



Sean

Douglas J. Steele said:
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)

The reason for the vbNullString is to ensure no problems if textName1
contains Null.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


neenmarie said:
I would like to have all the text currently in a textBox be selected when
it
receives focus so the user can enter or change data easily.

I've tried: [textName1].selectAll
And: Me.textName1.selectAll

selectAll isn't it....
how would I do this?
 
Good point.

I had that in the test I made before posting, but removed it to simplify the
solution. However, if the text box got focus by someone clicking in the
middle of the existing text, you're correct that it's necessary to set
SelStart to 0.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Sean said:
You may also add a Me.textName1.SelStart before, to ensure the cursor is
at the start of the string, before selection; so:

Me.textName1.SelStart = 0
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)



Sean

Douglas J. Steele said:
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)

The reason for the vbNullString is to ensure no problems if textName1
contains Null.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


neenmarie said:
I would like to have all the text currently in a textBox be selected
when it
receives focus so the user can enter or change data easily.

I've tried: [textName1].selectAll
And: Me.textName1.selectAll

selectAll isn't it....
how would I do this?
 
Thank you both for your response.
I put the following in the 'got focus' event. But, it did nothing at all.

Private Sub Text42_GotFocus()
Me.Text42.SelStart = 0
Me.Text42.SelLength = Len(Me.Text42 & vbNullString)
End Sub

Should it be a different event?


Douglas J. Steele said:
Good point.

I had that in the test I made before posting, but removed it to simplify the
solution. However, if the text box got focus by someone clicking in the
middle of the existing text, you're correct that it's necessary to set
SelStart to 0.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Sean said:
You may also add a Me.textName1.SelStart before, to ensure the cursor is
at the start of the string, before selection; so:

Me.textName1.SelStart = 0
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)



Sean

Douglas J. Steele said:
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)

The reason for the vbNullString is to ensure no problems if textName1
contains Null.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I would like to have all the text currently in a textBox be selected
when it
receives focus so the user can enter or change data easily.

I've tried: [textName1].selectAll
And: Me.textName1.selectAll

selectAll isn't it....
how would I do this?
 
You also have to consider how much of a PITA it'll be if the current data in
the field disappears! When all text is selected, hitting any key, even
inadvertently, will wipe it out! If you're gonna do a great deal of this, you
might want to consider adding an Undo button to your form.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
Thank you,
I'm using the form as a menu with criteria to open enter before opening
reports. Some of the fields are set with default criteria and/or the user
may want to change the criteria & open the report again with newly filtered
data.

I was able to empty the field by putting:
me.text40 = ""

I'd prefer to just have all the text selected and not have it empty the
field until they type in new data. But, this is better than nothing for now.
Thank you for your help
 
That's the identical code I used before sending my solution. However, I
didn't actually test the effect of clicking on the text box. When I did
that, I found I needed to put the code in the text box's Click event: while
the code fired in the GotFocus event, it would appear that the Click event
occurs after the GotFocus, and so where you clicked overrid that code.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


neenmarie said:
Thank you both for your response.
I put the following in the 'got focus' event. But, it did nothing at all.

Private Sub Text42_GotFocus()
Me.Text42.SelStart = 0
Me.Text42.SelLength = Len(Me.Text42 & vbNullString)
End Sub

Should it be a different event?


Douglas J. Steele said:
Good point.

I had that in the test I made before posting, but removed it to simplify
the
solution. However, if the text box got focus by someone clicking in the
middle of the existing text, you're correct that it's necessary to set
SelStart to 0.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Sean said:
You may also add a Me.textName1.SelStart before, to ensure the cursor
is
at the start of the string, before selection; so:

Me.textName1.SelStart = 0
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)



Sean

message
Me.textName1.SelLength = Len(Me.textName1 & vbNullString)

The reason for the vbNullString is to ensure no problems if textName1
contains Null.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I would like to have all the text currently in a textBox be selected
when it
receives focus so the user can enter or change data easily.

I've tried: [textName1].selectAll
And: Me.textName1.selectAll

selectAll isn't it....
how would I do this?
 
Back
Top