Give a try to this code:
Code:
Private Sub txtFromCityName_Change()
FltrStart "NameStud"
End Sub
Private Sub txtToCityName_Change()
FltrStart "Property_2"
End Sub
Private Sub FltrStart(strField As String)
Dim strText As String
On Error Resume Next
With Screen.ActiveControl
strText = .Text
Me.Filter = "[" & strField & "] LIKE ""*" & strText & "*"""
Me.FilterOn = Len(strText) > 0
.SetFocus
.SelStart = Len(strText) + 1
End With
End Sub
Edit:
If you don't want to pass the name of the field as argument, you have to keep it in the Tag property of the search control.
Then, the code above could be as follows:
Code:
Private Sub txtFromCityName_Change()
FltrStart
End Sub
Private Sub txtToCityName_Change()
FltrStart
End Sub
Private Sub FltrStart()
Dim strText As String
On Error Resume Next
With Screen.ActiveControl
strText = .Text
Me.Filter = "[" & .Tag & "] LIKE ""*" & strText & "*"""
Me.FilterOn = Len(strText) > 0
.SetFocus
.SelStart = Len(strText) + 1
End With
End Sub