Programatically place cursor insertion point at the end of Unbound Textbox field

S

spatelone

I've placed Unbound TextBox and subform to show records from a table.
By default when form stats all records are shown in subform.

As user enters 1 character at a time in Unbound TextBox the OnChange()
event is triggerred and I filter the records matching what user is
entering.

The problem I am facing is after the character is entered and records
are filtered when focus is back to Unbound Textbox:

The cursor is placed infront of the first character entered. I would
like to ensure the cursoer is at the end of the last character enered.

I did a lot or searching and reaching and I did made following
changes; however, no luck.

* In Tools, Options, Keyboard I updated to ensure entering field
behavior is end of the field
* I also wrote below code and don't work either:

Private Sub Srch_TXT_Enter()
Me.Srch_TXT.SelStart = Me.Srch_TXT.SelLength
End Sub

* I also written similar code on OnFocus()

Unfortunately, nothing seems to work and I am running out of ideas.

Can anyone please help?

I thank you in advance.
 
G

Guest

Try this code:
Dim lngSelLength As Long
lngSelLength = Len(Me.Srch_TXT.Value)
With Me.Srch_TXT
.SetFocus
.SelStart = lngSelLength
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top