G
GUhas
I am filtering in a form for either customer name or phone number. I have
the following expression for the Filter Command Button. I can find, for
example, 'pet' in the customer-name field and 'pet' can appear anywhere. I
can't figure out how to change the code so I only find 'pet' when it is the
1st word in the Customer-name or the last word; or I only get '603' when it
is the area code (start of the phone number) in Telephone. I am using Access
2007. I borrowed this code from http://allenbrowne.com/ser-62.html.
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
If Not IsNull(Me.txtAcctName) Then
strWhere = strWhere & "([customer-name] Like ""*" & Me.txtAcctName &
"*"") AND "
End If
If Not IsNull(Me.txtPhone) Then
strWhere = strWhere & "([telephone] Like ""*" & Me.txtPhone & "*"")
AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub
the following expression for the Filter Command Button. I can find, for
example, 'pet' in the customer-name field and 'pet' can appear anywhere. I
can't figure out how to change the code so I only find 'pet' when it is the
1st word in the Customer-name or the last word; or I only get '603' when it
is the area code (start of the phone number) in Telephone. I am using Access
2007. I borrowed this code from http://allenbrowne.com/ser-62.html.
Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long
If Not IsNull(Me.txtAcctName) Then
strWhere = strWhere & "([customer-name] Like ""*" & Me.txtAcctName &
"*"") AND "
End If
If Not IsNull(Me.txtPhone) Then
strWhere = strWhere & "([telephone] Like ""*" & Me.txtPhone & "*"")
AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
Me.Filter = strWhere
Me.FilterOn = True
End If
End Sub