I have a textbox that I use as a search field. To trigger the search, I use both an AfterUpdate event on the textbox and I have a button for those that are more mouse oriented.
Both the button's OnClick and the textbox's AfterUpdate events call the same private sub. In that subroutine I test the results to see if there was a match and if not, I do a .SetFocus back to the search textbox so that the user can retype a new value.
Problem: If the subroutine is called from the OnClick event of the textbox, then the cursor goes to the beginning of the field instead of selecting the whole field.
If the subroutine is called from the button's OnClick event, then the whole field is selected like I want.
I did check Access's setting for what to do when entering a field and it is set to select the whole field. I initially thought that it was because the control already had focus if I triggered the subroutine from the textbox's AfterUpdate event, so I tried having it set focus on the button and then going back to the textbox. There was no change for either method of triggering the subroutine so I took it back out.
Here is my code:
Both events that call this subroutine, only call the subroutine and nothing else so there is no other code that is ran.
I'm out of ideas.
Both the button's OnClick and the textbox's AfterUpdate events call the same private sub. In that subroutine I test the results to see if there was a match and if not, I do a .SetFocus back to the search textbox so that the user can retype a new value.
Problem: If the subroutine is called from the OnClick event of the textbox, then the cursor goes to the beginning of the field instead of selecting the whole field.
If the subroutine is called from the button's OnClick event, then the whole field is selected like I want.
I did check Access's setting for what to do when entering a field and it is set to select the whole field. I initially thought that it was because the control already had focus if I triggered the subroutine from the textbox's AfterUpdate event, so I tried having it set focus on the button and then going back to the textbox. There was no change for either method of triggering the subroutine so I took it back out.
Here is my code:
Code:
Private Sub FindLoan()
If Me.txtLoanNumberSearch & "" <> "" Then
Me.Recordset.FindFirst "LoanNumber = " & Me.txtLoanNumberSearch
If Me.Recordset.NoMatch Then
Me.imgWarning.Visible = True
Me.lblInvalidLoanNumber.Visible = True
DoCmd.GoToRecord , , acNewRec
Me.txtLoanNumberSearch.SetFocus
Else
Me.imgWarning.Visible = False
Me.lblInvalidLoanNumber.Visible = False
Me.txtLoanNumberSearch = ""
End If
End If
End Sub
I'm out of ideas.
Comment