select entire text in textbox

K

Keith G Hicks

(A2003)

I know if I tab to a text box the entire text is selected but when I click
into a text box with a mask, the cursor is placed where I put it rather than
selecting the entire text box. this is a problem when masking for currency
for example. My mask is this: 999999.99

If I tab to the text box, I can type a number then a period then a number
and the decimal ends up in the right place and all seems good. But when I
click into the text box with the mouse, things go astray. I think it would
help to select the entire text regardless of whether the user tabs or clicks
into the box. But I can't seem to find out how to select the text. I tried
this:

Private Sub PkgCommAmtRcvd_Enter()
Me.PkgCommAmtRcvd.SelStart = 0
Me.PkgCommAmtRcvd.SelLength = 100
End Sub

But when I click into the box it still just selects 1 character. How can I
force it to always select the entire text?

Thanks,

Keith
 
C

Clifford Bass

Hi Keith,

The order of events when you click in a field is Enter, GotFocus,
Click. The order of events when you tab into a field is Enter, GotFocus. So
the click gets processed after you set the selection. I would suggest this:

Private Sub PkgCommAmtRcvd_GotFocus()

With PkgCommAmtRcvd
.SelStart = 0
.SelLength = Len(Nz(PkgCommAmtRcvd.InputMask, "")) + 1
End With

End Sub

Private Sub PkgCommAmtRcvd_Click()

PkgCommAmtRcvd_GotFocus

End Sub

Clifford Bass
 
K

Keith G Hicks

That did it. Than you. :)

Clifford Bass said:
Hi Keith,

The order of events when you click in a field is Enter, GotFocus,
Click. The order of events when you tab into a field is Enter, GotFocus.
So
the click gets processed after you set the selection. I would suggest
this:

Private Sub PkgCommAmtRcvd_GotFocus()

With PkgCommAmtRcvd
.SelStart = 0
.SelLength = Len(Nz(PkgCommAmtRcvd.InputMask, "")) + 1
End With

End Sub

Private Sub PkgCommAmtRcvd_Click()

PkgCommAmtRcvd_GotFocus

End Sub

Clifford Bass
 

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