wackywoo105
Registered User.
- Local time
- Today, 12:35
- Joined
- Mar 14, 2014
- Messages
- 203
I have a field for first and last name. I can currently filter records based on last name. I want to make it so I can also type in the first name or initial after the full or part of the surname and it will filter appropriately.
e.g. Paul Clarke would be shown if I typed “Cla Pa” and clicked filter.
Here is the code I have been playing with. The debug shows the names are pulled out ok. Im struggling to write the Me.Filter query. I just says no current record. I haven’t yet put the wildcards in so I could just type “c p” into the filter text box and it would return Paul Clarke.
Any help on this would be greatly appreciated. Also I have no idea of placing quotation marks etc. Is there any online resource I could refer to so I can learn?
e.g. Paul Clarke would be shown if I typed “Cla Pa” and clicked filter.
Here is the code I have been playing with. The debug shows the names are pulled out ok. Im struggling to write the Me.Filter query. I just says no current record. I haven’t yet put the wildcards in so I could just type “c p” into the filter text box and it would return Paul Clarke.
Code:
Private Sub FilterON_Click()
Me.FilterON = False
Dim nSpace As Integer
nSpace = InStrRev(Me![Filter], " ")
If nSpace = 0 Then
Me.Filter = "[surname] like '" & Me![Filter] & "*'"
GoTo nospace
End If
Dim last As String
Dim first As String
last = Left(Me![Filter], InStr(Me![Filter], " ") - 1)
first = Right(Me![Filter], Len(Me![Filter]) - InStrRev(Me![Filter], " "))
Debug.Print last
Debug.Print first
Me.Filter = "[Surname] like " & last & " And [First Names] like " & first
nospace:
Me.FilterON = True
End Sub
Last edited: