I have the following code,
Code:
Private Sub txtNameFilter_KeyUp(KeyCode As Integer, Shift As Integer)
On Error GoTo errHandler
Dim filterText As String
'Apply or update filter based on user input
If Len(txtNameFilter.Text) > 0 Then
filterText = txtNameFilter.Text
Me.Form.Filter = "[CompanyName] LIKE '*" & filterText & "*'OR [TradingCompanyName] LIKE '*" & filterText & "*'"
Me.FilterOn = True
'Retain filter text in search box after refresh.
txtNameFilter.Text = filterText
txtNameFilter.SelStart = Len(txtNameFilter.Text)
Else
' Remove filter.
Me.Filter = ""
Me.FilterOn = False
txtNameFilter.SetFocus
End If
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly, "Error ..."
End Sub
However if I search for: 5 Star because there is a space I get an error, however I have tried:
Code:
txtNameFilter.SelStart = Len(Replace(txtNameFilter.Text, " ", "."))
Instead of
Code:
txtNameFilter.SelStart = Len(txtNameFilter.Text)
However still get Error 2185 You can't reference a property or method for a control unless the control has focus
I have the unbound control on the form I am searching, its a continuous form which has a Query Control Source.
Does anyone have any suggestions?