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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select text in textbox

Status
Not open for further replies.

andzejek

MIS
Sep 1, 2007
154
US
I have a textbox formatted to currency with two dec. places. How to use selLenght to select whole field? Me.textbox.selLength=12(width of the field in the table) is highlighting only decimal places.

Andrew
 
Me.textbox.selStart = 0
Me.textbox.selLength = Len(Me.textbox)

Should do the trick.....

Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes.
 
I did try that, it is highlighting only decimal places.
 
I did a little testing on this. If the data is in the table is "12" and it is displaying "$12.00" then length of me.textbox returns 2 not 6. So I tried
With txtPrice
.SelStart = 0
.SelLength = Len(txtPrice) + 4
End With
but that only worked if I had integer data in the table
did not work if I had data like, 123.456, or 123.4
So I tried this which seems to work, but there has to be a much easier solution.
With txtPrice
.SelStart = 0
.SelLength = Len(Left(txtPrice.Text, InStr(txtPrice.Text, "."))) + 2
End With
 
It is not working, still highlighting only decimal places. This field is normally locked, with doubleclick I want to unlock it and highlite whole text. Unlocking is working, highliting not.
 
How about
Code:
Me.textbox.selStart = 0
Me.textbox.selLength = Len(CStr(Me.textbox))

Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes.
 
Sorry, but still this same. Depending whee I'm clicking it is highliting places before or after decimal point but not whole field.

Andrew
 
Too weird - all three work fine for me. Works when the control gets focus (tab into it), not on the click event.
Maybe the code needs to be moved to another event? Clicking in the text box will place the cursor, which could be messing the length? All out of suggestions here so far, but I'll keep an eye on the thread.
Good luck!

Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes.
 
In which event procedure ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Form Load will highlight it immediately. Haven't tried the GotFocus event of the text box, but that would seem logical...

Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes.
 
DblClick - This field is normally locked, with doubleclick I want to unlock it and highlite whole text. Unlocking is working, highliting not.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top