Keep mouse cursor at the end of text box after ON CHANGE Event Procedure

pckong

Registered User.
Local time
Tomorrow, 06:59
Joined
Jul 3, 2013
Messages
14
Hi all,

Here is my problem. I made an On Change Procedure on a textbox, so everytime I input a character, it will trigger the Me.Requery.

However, after that the event, the mouse cursor moved to the beginning of other field. I want it to stay at the end of the textbox so I can enter a full word, how do I do that?

Code:
Private Sub Text73_Change()
     ProjectSearch = Me.Text73
     Me.Filter = "[Project Name] Like " & Chr(34) & ProjectSearch & "*" & Chr(34)
     Me.FilterOn=True
     Me.Requery
End Sub
 
Try the below:

Code:
Private Sub Text73_Change()      
ProjectSearch = Me.Text73      
Me.Filter = "[Project Name] Like " & Chr(34) & ProjectSearch & "*" & Chr(34)     
Me.FilterOn=True      
Me.Requery 
Me.Text73.SetFocus
If Not IsNull(Me.Text73) Then
    Me.Text73.SelStart = Len(Me.Text73)
End If
 
Thank you very much for the reply JHB. It works as intended.
I have an additional problem. The above code ignore Space Bar input. Are there any ways to accept the space bar input as in the search field, I might need to type in a phrase.
 
Replace the code you have with the below:
Code:
Dim KeyIsPressed As Boolean
Dim RememberText As String

Private Sub Text73_Change()
  If KeyIsPressed Then
    RememberText = Me.Text73.Text
  End If
  Me.Filter = "[First Name] Like " & Chr(34) & Text73.Text & "*" & Chr(34)
  Me.FilterOn = True
  Me.Requery
  Text73.SetFocus
  If Not IsNull(Me.Text73.Text) And KeyIsPressed Then
    KeyIsPressed = False
    Me.Text73 = RememberText
    Text73.SelStart = Len(Me.Text73) 
  End If
End Sub

Private Sub Text73_KeyDown(KeyCode As Integer, Shift As Integer)
  KeyIsPressed = True
End Sub
 

Users who are viewing this thread

Back
Top Bottom