Solved Using SelStart on a ComboBox with an Input Mask (1 Viewer)

Richard Horne

Member
Local time
Today, 22:08
Joined
Oct 15, 2020
Messages
55
So there are a thousand threads on how to use SelStart but I'm so far unable to find one that tells me how to make it work where a combo box has an input mask.

I'm using Access 365.

My combo box is called cbo_nsn_filter. My onClick event code is:

Code:
Private Sub cbo_nsn_filter_Click()

Me.cbo_nsn_filter.SetFocus
Me.cbo_nsn_filter.SelStart = 0

End Sub

I've tried with and without SetFocus. I've also tried using SendKeys but that didn't work either.

My input mask is: 0000\-00\-000\-0000;0;

But no matter what I do, SelStart does not set the cursor to the start of the combo.

Any suggestions?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:08
Joined
Oct 29, 2018
Messages
21,474
Your combo has an input mask? Are you using the combo to add new items to its list?
 

Richard Horne

Member
Local time
Today, 22:08
Joined
Oct 15, 2020
Messages
55
Yeah it has an input mask. Not allowing additions to the list, no.

NSNs are usually in this format: 1234-12-123-1234
I use an input mask so my users don't have to type the hypens. This allows them to just type 1234121231234 and the hypens are added automatically.

But annoyingly, when you click in the field and start typing the cursor ends up wherever you clicked in the middle of the field and not at the start.

Try recreate it yourself and you'll find it does the same for you. It's frustrating because every post is just people saying use SelStart.
 

Richard Horne

Member
Local time
Today, 22:08
Joined
Oct 15, 2020
Messages
55
OK, so rather hilariously this works if you use the MouseUp event, but not OnClick. Turns out I'd figured this out elsewhere in my project but had no recollection of it.

Code:
Private Sub cbo_nsn_filter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.cbo_nsn_filter.SelStart = 0
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 22:08
Joined
Sep 21, 2011
Messages
14,310
But annoyingly, when you click in the field and start typing the cursor ends up wherever you clicked in the middle of the field and not at the start.
That is the main reason I absolutely hate input masks. I'd rather format it myself in the AfterUpdate or elsewhere.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:08
Joined
Oct 29, 2018
Messages
21,474
OK, so rather hilariously this works if you use the MouseUp event, but not OnClick. Turns out I'd figured this out elsewhere in my project but had no recollection of it.

Code:
Private Sub cbo_nsn_filter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.cbo_nsn_filter.SelStart = 0
End Sub
I see what you mean. Glad to hear you got it sorted out. Good luck!
 

Users who are viewing this thread

Top Bottom