Just like PythonF in 2019, I am currently working on a database with MS Access 365. I am using the filtering of access to create a live-search in my form. Seems to work fine until I type something in that is not contained in the database. Getting runtime error 2185 instead of just giving an empty result. 'You can't reference a property or method for a control unless the control has the focus'. My code:
Option Compare Database
Private blnSpace As Boolean
Private Sub Form_Load()
Me.SearchText.SetFocus
End Sub
Private Sub Refresh_Click()
With Me
SearchText = ""
End With
Me.SearchText.SetFocus
End Sub
Private Sub SearchText_Change()
If blnSpace = False Then
Me.Requery
Refresh
SearchText.SetFocus
SearchText.SelStart = Len(Me.SearchText.Text)
End If
End Sub
Private Sub SearchText_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then
blnSpace = True
Else
blnSpace = False
End If
End Sub
Added PythonF's code:
If Not (Me.Recordset.RecordCount = 0) Then
Me.SearchBox.SelStart = SearchLen
End If
Added Dim SearchLen when it did not recognize the variable SearchLen
Would like to see PythonF's solution - he only said he fixed it but did not share the code that finally worked.