textbox selection

  • Thread starter Thread starter george
  • Start date Start date
G

george

Hi,

I use the following code to select the whole text in my
LName textbox when I click on it:


if not isnull(LName) then
me.LName.selstart = 0
me.LName.sellenght = len(me.LName)
end if

Now I would like to add an extra feature. If I clicked for
a second time on (the already selected) text I would like
the text to be deselected and the cursor to be inserted in
the place I clicked. How do I do this?

Also can someone explain why the above mentioned code
doesn't work for combo boxes?

Any help greatly appreciated.
Thanks in advance, george
 
Hi,
You can try this:

Static bSelectAll As Boolean
If Not IsNull(Me.LName) And Not bSelectAll Then
Me.LName.SelStart = 0
Me.LName.SelLength = Len(Me.LName)
bSelectAll = True
Else
bSelectAll = False
End If

With the above, if the whole text is selected, then when you click again, the cursor will
simply be placed where you clicked and no text is selected. If you then click again, the whole text
will be selected. If you only want the whole text to be selected the first time you click (and never again),
remove the Else portion of the code.
 
Back
Top