I am encountering a Runtime error 2185 You can't reference a property or method for a control unless the control has focus after typing a filter in a combobox which returns no records that is running the following code:
Private Sub cboFilter_Change()
If Me.cboFilter = "" Then
Me.Form.Filter = ""
Me.FilterOn = False
ElseIf Me.cboFilter.ListIndex <> -1 Then
Me.Form.Filter = "[Lastname] = '" & _
Replace(Me.cboFilter.Text, "'", "''") & "'"
Me.FilterOn = True
Else
Me.Form.Filter = "[Lastname] Like '*" & _
Replace(Me.cboFilter.Text, "'", "''") & "*'"
Me.FilterOn = True
End If
Me.cboFilter.SetFocus
Me.cboFilter.SelStart = Nz(Len(Me.cboFilter))
End Sub
The line with the .Selstart object is the one highlighted on Debug. I am only baffled as I have already implemented this code on multiple occasions on different Access databases before and it is only now that I encountered this error. Before, typing in
text that will result in no records will do just that - show no records. Now, it only results in this error.
Perhaps I have seen in this method in this post in the Access blog. And found in the comments below
is a problem exactly the same as mine, but the author did not reply. I do not want to make a workaround. I want to understand why this is happening now, but not before.
Please help!
Ome