Using SelStart with a ComboBox (1 Viewer)

HairyArse

Registered User.
Local time
Today, 05:43
Joined
Mar 31, 2005
Messages
92
I have a combo box formatted with an input mask of:

####\-##\-###\-####;0;

When the user clicks in the combo box, usually the cursor ends up in the middle of the string and they have to backspace or press the Home key to return to the start of the field.

I know that for a text field you can automatically move the cursor to the start by using me.control.SelStart = 0 in the On Got Focus event. However, this doesn't work for a combo box.

I've tried on click, on enter and on got focus.
 

June7

AWF VIP
Local time
Yesterday, 21:43
Joined
Mar 9, 2014
Messages
5,424
It does work for combobox. I use it.

Private Sub cbxSample_Enter()
If Not IsNull(Me.cbxSample) Then Me.cbxSample.SelStart = Len(Me.cbxSample)
Me.cbxSample.Dropdown
End Sub
 

HairyArse

Registered User.
Local time
Today, 05:43
Joined
Mar 31, 2005
Messages
92
I've tried the following in the On Enter event and it doesn't work for me. Access 2013.

'Move the cursor to the start of the cbo if empty
If IsNull(Me.cbo_nsn) Or (Me.cbo_nsn = "") Then
Me.cbo_nsn.SelStart = 0
End If

I've even tried adding .Column(1) as my cbo_nsn field has the id hidden but this makes no difference.

If IsNull(Me.cbo_nsn) Or (Me.cbo_nsn = "") Then
Me.cbo_nsn.Column(1).SelStart = 0
End If
 

HairyArse

Registered User.
Local time
Today, 05:43
Joined
Mar 31, 2005
Messages
92
I've also tried your code and it makes no difference.
 

Minty

AWF VIP
Local time
Today, 05:43
Joined
Jul 26, 2013
Messages
10,355
I suspect it's the input mask over-riding the normal behaviour.

Why do you need it? Shirley a combo is already presenting the data as you need it?
 

isladogs

MVP / VIP
Local time
Today, 05:43
Joined
Jan 14, 2017
Messages
18,186
Minty beat ne to it. Try removing the input mask at least temporarily.
Also have you checked the default behaviour in the client settings of Access options?
 

HairyArse

Registered User.
Local time
Today, 05:43
Joined
Mar 31, 2005
Messages
92
You're right. Removing the input mask sorts it.

The input mask is just to stop my users having to type hyphens but I think it's a small price to pay to have the cursor in the correct place.

Thanks guys. :)
 

HairyArse

Registered User.
Local time
Today, 05:43
Joined
Mar 31, 2005
Messages
92
Actually, removing the input mask doesn't technically sort it. It's just that without the input mask it's impossible for the cursor to be anywhere other than at the start.
 

isladogs

MVP / VIP
Local time
Today, 05:43
Joined
Jan 14, 2017
Messages
18,186
Not if you change the client settings as I suggested. However that has to be done on each workstation


Sent from my iPhone using Tapatalk
 

Users who are viewing this thread

Top Bottom