Is this a bug? SelLength with ComboBox

  • Thread starter Thread starter Perico
  • Start date Start date
P

Perico

I am still having a problem with this code relating to an
unbound combobox - it does not select the text as it
should:

Private Sub cboDistrict_GotFocus()
Me.cboDistrict.SelStart = 0
Me.cboDistrict.SelLength = Len(Me.cboDistrict.Text)
End Sub

How can I get the text in the combobox to be
selected properly? This is Access2K.
 
The code you supply will firstly deselect the text in the combobox, then
count the characters in it, then select them entirely... Why? When you enter
a field you can select all the text anyway... Tools:Options:Keyboard...
Select Entire Field... Anyway, in your code, use Len(Me.cboDistrict) instead
of Len(Me.cboDistrict.Text)...

HTH.

Tom.
 
That tools option was selected, but nonetheless, when you
click on the field with the mouse, it doesn't select the
entire field. I'll try the code modification you suggest.
-----Original Message-----
The code you supply will firstly deselect the text in the combobox, then
count the characters in it, then select them entirely... Why? When you enter
a field you can select all the text anyway... Tools:Options:Keyboard...
Select Entire Field... Anyway, in your code, use Len (Me.cboDistrict) instead
of Len(Me.cboDistrict.Text)...

HTH.

Tom.
 
Perico said:
That tools option was selected, but nonetheless, when you
click on the field with the mouse, it doesn't select the
entire field. I'll try the code modification you suggest.

This the first time that you've mentioned clicking in the control. If
that's the only circumstance in which the selection doesn't come out the
way you want, then it's not a bug -- it's just an undesirable feature!
You are correctly selecting the text when the control gets the focus,
but then the text box receives the mouse click, and its response to that
is to unselect the text and put the caret (text insertion point) at the
location that was clicked.

AFAIK you can't turn off this behavior. If the control is a text box,
you should be able to work around it by putting code in the control's
Click event to select the text again. If the control is a combo box,
though, I don't think this will work as a combo box doesn't fire the
Click event the same way -- it only fires it in response to a change to
the combo's Value.
 
Back
Top