Having problem with the selstart option

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

Guest

I have a combo box that in the gotfocus event I have set the following code:
me!cmbAlias.dropdown this works great when I tab into the field but when I
just click in the field the cursor is set to position 1. I've set the
SelStart to = 0 in both the Enter event and also in the Gotfocus event and
have tried it in the Click event but no matter what if I just click in that
field it always starts at position 1 and I have to press the backspace key to
get to the beginning of the field. Can anyone give me some idea what's
causing this and how to fix it.
Thanks
CD Tom
 
I suspect it's because you are clicking at position 1 ;-)

I've just done a bit of testing, and it seems that there is no way to do
this, apart from clicking at position 0 in the field. When you click in a
control (textbox, combobox, ... ) the SelStart parameter is not used, as it
is when you tab into the control. Setting SelStart in the GotFocus event
works fine if you enter the combobox by tabbing to it (as you say).

The Click event will not help you; for a combobox it occurs when an entry in
the dropdown list is selected by clicking it. The Enter event is similar to
the GotFocus event (it occurs before it - see Help file), but again, the
clicked position overrides any SelStart parameter. I also tried the
MouseDown event (with an If statement to run the code on left button click),
which also failed.

I found that clicking in a combobox which does not have focus gives:
GotFocus event, in which I can set SelStart to 0 (confirmed via message
box), then
MouseDown event, in which I can set SelStart to 0 (confirmed via message
box)
and THEN the selstart moves to where I clicked!!! I also tried adding a
DoEvents, to see if that would help, but no joy.

So, it seems that you simply do have to click at position 0.

BTW, you might find the MouseDown event useful, since you can use:
If Button = acLeftButton Then cmbAlias.Dropdown
If you simply want to select an existing entry (which I suspect you do,
since you are already using the Dropdown method in the GotFocus event), then
this may be enough, even though the SelStart is at the position you click.

HTH,

Rob
 
Back
Top