Hi, folks. I have a form in which the AllowAdditions property is set to false.
On same form, I also have 3 unbound text boxes in the header which are used as search boxes- they allow users to filter as they type.
The problem is, if the user types something into one of the search boxes that returns zero records, it triggers "Run Time Error 2185: You Can't Reference A Property or Method for a Control Unless the Control Has the Focus." This occurs even though the search box control DOES have the focus.
Here's the code for one of the search boxes, named FilterFirstName:
Code:
If Trim(FilterFirstName.Text & "") = vbNullString And IsNull(FilterLastName) And IsNull(FilterPhones) Then
Me.Filter = ""
Me.FilterOn = False
Me.FilterFirstName.SetFocus
Else
Me.Filter = "FirstName Like '*" & FilterFirstName.Text & "*'" & _
" And LastName Like '*" & FilterLastName & "*'" & _
" And Phones Like '*" & FilterPhones & "*'"
Me.FilterOn = True
Me.FilterFirstName.SelStart = FilterFirstName.SelLength
End If
The line that triggers the error is:
Code:
Me.FilterFirstName.SelStart = FilterFirstName.SelLength
And when the users types another letter in the text box or deletes a letter, the error triggers earlier, at this line:
Code:
If Trim(FilterFirstName.Text & "") = vbNullString And IsNull(FilterLastName) And IsNull(FilterPhones) Then
Any ideas for how to fix this? Thanks so much!
Matt