I'm trying to have a command button look up based on 2 criteria based on
first & last names. Works fine if I'm doing one or the other:
Dim FIRSTNAMEEXPR As Variant
Dim LASTNAMEEXPR As Variant
(the FIRSTNAMEEXPR and LASTNAMEEXPR are expressions that I have (work fine)
that have pared down names to get rid of middle initials, Jr., Sr. etc.... I
didn't put whole thing here)
Me.Filter = "[first] Like'" & FIRSTNAMEEXPR & "'" And "[last] Like'" &
LASTNAMEEXPR & "'"
Me.FilterOn = True
also, is there a way to do "Or"?
Many thanks!

Signature
tgl
Sprinks - 26 Jul 2005 21:06 GMT
Hi, tgl.
AND needs to be part of your string expression that you set the filter to.
Rearrange your quotes so that it is cast as a string literal:
Me.Filter = "[First] Like'" & FIRSTNAMEEXPR & "' And [Last] Like'" & _
LASTNAMEEXPR & "'"
Me.FilterOn = True
Hope that helps.
Sprinks
> I'm trying to have a command button look up based on 2 criteria based on
> first & last names. Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!
Sprinks - 26 Jul 2005 21:07 GMT
tgl,
Forgot to mention, you can use OR the same way.
Sprinks
> I'm trying to have a command button look up based on 2 criteria based on
> first & last names. Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!
fredg - 26 Jul 2005 21:07 GMT
> I'm trying to have a command button look up based on 2 criteria based on
> first & last names. Works fine if I'm doing one or the other:
[quoted text clipped - 13 lines]
>
> Many thanks!
Too many double quotes.
I've added a space between the single and double quotes for clarity.
Remove the spaces when using the code. Also add a space after Like and
the ' so Access recognizes the word.
Me.Filter = "[first] Like ' " & FIRSTNAMEEXPR & " ' And [last] Like
' " & LASTNAMEEXPR & " ' "
Me.FilterOn = True

Signature
Fred
Please only reply to this newsgroup.
I do not reply to personal email.